ErrorProvider Demo : ErrorProvider « GUI Form « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » GUI Form » ErrorProvider 
ErrorProvider Demo
 

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
  Application::Run(gcnew Form1());
  return 0;
}

  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;

  public ref class Form1 : public System::Windows::Forms::Form
  {
  public:
    Form1(void)
    {
      InitializeComponent();
    }

  private:
        System::Windows::Forms::TextBox^  tbPword;
        System::Windows::Forms::Label^  lbPword;
        System::Windows::Forms::Button^  bnLogin;
        System::Windows::Forms::TextBox^  tbName;
        System::Windows::Forms::Label^  lbName;
        System::Windows::Forms::ErrorProvider^  eProvider;

    void InitializeComponent(void)
    {
            this->tbPword = (gcnew System::Windows::Forms::TextBox());
            this->lbPword = (gcnew System::Windows::Forms::Label());
            this->bnLogin = (gcnew System::Windows::Forms::Button());
            this->tbName = (gcnew System::Windows::Forms::TextBox());
            this->lbName = (gcnew System::Windows::Forms::Label());
            this->eProvider =(gcnew System::Windows::Forms::ErrorProvider());

            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>
                (this->eProvider))->BeginInit();
            this->SuspendLayout();
            //
            // tbPword
            //
            this->tbPword->Location = System::Drawing::Point(10383);
            this->tbPword->Name = L"tbPword";
            this->tbPword->PasswordChar = '*';
            this->tbPword->Size = System::Drawing::Size(10020);
            this->tbPword->TabIndex = 9;
            this->tbPword->Validating +=
                gcnew System::ComponentModel::CancelEventHandler(this,
                                                   &Form1::textbox_Validating);
            //
            // lbPword
            //
            this->lbPword->AutoSize = true;
            this->lbPword->Location = System::Drawing::Point(3483);
            this->lbPword->Name = L"lbPword";
            this->lbPword->Size = System::Drawing::Size(5313);
            this->lbPword->TabIndex = 8;
            this->lbPword->Text = L"&Password";
            //
            // bnLogin
            //
            this->bnLogin->Location = System::Drawing::Point(75131);
            this->bnLogin->Name = L"bnLogin";
            this->bnLogin->Size = System::Drawing::Size(7523);
            this->bnLogin->TabIndex = 7;
            this->bnLogin->Text = L"&Login";
            this->bnLogin->Click +=
                gcnew System::EventHandler(this, &Form1::login_Click);
            //
            // tbName
            //
            this->tbName->Location = System::Drawing::Point(10331);
            this->tbName->Name = L"tbName";
            this->tbName->Size = System::Drawing::Size(10020);
            this->tbName->TabIndex = 6;
            this->tbName->Validating +=
                gcnew System::ComponentModel::CancelEventHandler(this,
                                                   &Form1::textbox_Validating);
            //
            // lbName
            //
            this->lbName->AutoSize = true;
            this->lbName->Location = System::Drawing::Point(3431);
            this->lbName->Name = L"lbName";
            this->lbName->Size = System::Drawing::Size(3513);
            this->lbName->TabIndex = 5;
            this->lbName->Text = L"&Name";

            //
            // eProvider
            //
            this->eProvider->ContainerControl = this;
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(613);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(237185);
            this->Controls->Add(this->tbPword);
            this->Controls->Add(this->lbPword);
            this->Controls->Add(this->bnLogin);
            this->Controls->Add(this->tbName);
            this->Controls->Add(this->lbName);
            this->Name = L"Form1";
            this->Text = L"System Login";
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>
                (this->eProvider))->EndInit();
            this->ResumeLayout(false);
            this->PerformLayout();
    }
        System::Void textbox_Validating(System::Object^ sender,
                                    System::ComponentModel::CancelEventArgs^ e)
        {
            try
            {
                TextBox ^tb = (TextBox^)(sender);

                if (tb->Text->Equals(""))
                    eProvider->SetError(tb, "**Error** Missing Entry!");
                else
                    eProvider->SetError(tb, "");
            }
            catch (Exception^)
            {
                // Not TextBox
            }
        }

        System::Void login_Click(System::Object^ sender, System::EventArgs^ e)
        {
            if (tbName->Text->Equals(""))
                eProvider->SetError(tbName, "**Error** Missing Entry!");
            else
                eProvider->SetError(tbName, "");


            if (tbPword->Text->Equals(""))
            {
                // Place the icon left side of control
                eProvider->SetIconAlignment(tbPword,
                                            ErrorIconAlignment::MiddleLeft);
                eProvider->SetError(tbPword, "**Error** Missing Entry!");
            }
            else
                eProvider->SetError(tbPword, "");
        }
  };
}

   
  
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.