Text Entry : TextBox « 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 » TextBox 
Text Entry
 

  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();

            DoB = DateTime::MinValue;

            // setting validating type to DateTime
            mtbDoB->ValidatingType = DateTime::typeid;
    }

  protected:
        System::Windows::Forms::Button^  bnSubmit;
        System::Windows::Forms::Label^  label3;
        System::Windows::Forms::TextBox^  tbPassword;
        System::Windows::Forms::TextBox^  tbOutput;
        System::Windows::Forms::Label^  label2;
        System::Windows::Forms::MaskedTextBox^  mtbDoB;
        System::Windows::Forms::Label^  label1;
        System::Windows::Forms::TextBox^  tbName;

        DateTime^ DoB;

    void InitializeComponent(void)
    {
            this->bnSubmit = (gcnew System::Windows::Forms::Button());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->tbPassword = (gcnew System::Windows::Forms::TextBox());
            this->tbOutput = (gcnew System::Windows::Forms::TextBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->mtbDoB = (gcnew System::Windows::Forms::MaskedTextBox());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->tbName = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // bnSubmit
            // 
            this->bnSubmit->Location = System::Drawing::Point(26036);
            this->bnSubmit->Margin = System::Windows::Forms::Padding(1,3,3,3);
            this->bnSubmit->Name = L"bnSubmit";
            this->bnSubmit->Size = System::Drawing::Size(5620);
            this->bnSubmit->TabIndex = 10;
            this->bnSubmit->Text = L" Submit";
            this->bnSubmit->Click += 
                gcnew System::EventHandler(this, &Form1::bnSubmit_Click);
            // 
            // label3

            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(14232);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(5613);
            this->label3->TabIndex = 14;
            this->label3->Text = L"Password:";
            // 
            // tbPassword
            // 
            this->tbPassword->CausesValidation = false;
            this->tbPassword->Location = System::Drawing::Point(78226);
            this->tbPassword->MaxLength = 16;
            this->tbPassword->Name = L"tbPassword";
            this->tbPassword->PasswordChar = '?';
            this->tbPassword->Size = System::Drawing::Size(23820);
            this->tbPassword->TabIndex = 13;
            this->tbPassword->UseSystemPasswordChar = true;
            this->tbPassword->WordWrap = false;
            this->tbPassword->TextChanged += 
               gcnew System::EventHandler(this,&Form1::tbPassword_TextChanged);
            // 
            // tbOutput
            // 
            this->tbOutput->Location = System::Drawing::Point(1463);
            this->tbOutput->Multiline = true;
            this->tbOutput->Name = L"tbOutput";
            this->tbOutput->ReadOnly = true;
            this->tbOutput->ScrollBars = 
                System::Windows::Forms::ScrollBars::Vertical;
            this->tbOutput->Size = System::Drawing::Size(302156);
            this->tbOutput->TabIndex = 12;
            this->tbOutput->TabStop = false;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(16815);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(6913);
            this->label2->TabIndex = 11;
            this->label2->Text = L"Date of Birth:";
            // 
            // mtbDoB
            // 
            this->mtbDoB->AllowPromptAsInput = false;
            this->mtbDoB->BeepOnError = true;
            this->mtbDoB->Location = System::Drawing::Point(16836);
            this->mtbDoB->Margin = System::Windows::Forms::Padding(3,3,1,3);
            this->mtbDoB->Mask = L"00/00/0000";
            this->mtbDoB->Name = L"mtbDoB";
            this->mtbDoB->Size = System::Drawing::Size(8920);
            this->mtbDoB->TabIndex = 8;
            this->mtbDoB->TypeValidationCompleted += 
                gcnew System::Windows::Forms::TypeValidationEventHandler(this,
                                      &Form1::mtbDoB_TypeValidationCompleted);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(1415);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(3813);
            this->label1->TabIndex = 9;
            this->label1->Text = L"Name:";
            // 
            // tbName
            // 
            this->tbName->Location = System::Drawing::Point(1436);
            this->tbName->Name = L"tbName";
            this->tbName->Size = System::Drawing::Size(14720);
            this->tbName->TabIndex = 7;
            this->tbName->Validating += 
                gcnew System::ComponentModel::CancelEventHandler(this, 
                                                   &Form1::tbName_Validating);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(613);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(331261);
            this->Controls->Add(this->bnSubmit);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->tbPassword);
            this->Controls->Add(this->tbOutput);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->mtbDoB);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->tbName);
            this->Name = L"Form1";
            this->Text = L"Simple entry data entry";
            this->ResumeLayout(false);
            this->PerformLayout();
    }
    private
        System::Void bnSubmit_Click(System::Object^ sender, System::EventArgs^ e)
        {
            if (tbName->Text->Length <= 0)          // Blank name bad!
                tbName->Focus();
            else if (*DoB == DateTime::MinValue)    // Bad date bad!
                mtbDoB->Focus();

            else                                    // Good!
            {
                // Concatinate name and date of birth and add to output
                tbOutput->Text = String::Format("{0} - {1}\r\n{2}"
                    tbName->Text, mtbDoB->Text, tbOutput->Text);
                tbName->Clear()
                mtbDoB->Clear();
                DoB = DateTime::MinValue;
           }
        }

        System::Void tbPassword_TextChanged(System::Object^ sender, System::EventArgs^ e)
        {
            if (tbPassword->Text->Equals("Editable")) 
            {
                tbOutput->TabStop = true;
                tbOutput->ReadOnly = false
            }
            else
            {
                tbOutput->TabStop = false;
                tbOutput->ReadOnly = true
            }
        }

        System::Void mtbDoB_TypeValidationCompleted(System::Object^ sender, System::Windows::Forms::TypeValidationEventArgs^ e)
        {
            if (e->IsValidInput && 
                (*(DateTime^)e->ReturnValue<= DateTime::Now)
            {
                DoB = (DateTime^)e->ReturnValue;
                mtbDoB->BackColor = SystemColors::Window;
            }
            else
            {
                mtbDoB->BackColor = Color::Yellow;
                DoB = DateTime::MinValue;
            }
        }


        System::Void tbName_Validating(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e)
        {
            if (tbName->Text->Length <= 0)
                tbName->BackColor = Color::Yellow;
            else
                tbName->BackColor = SystemColors::Window;
        }
  };


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

   
  
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.