C++ Visual.net : GUI Form ex 2

 1 StatusStrip Demo

 


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

        System::Windows::Forms::ToolStripContainer^  tsContainer;
        System::Windows::Forms::StatusStrip^  statusStrip1;
        System::Windows::Forms::ToolStripStatusLabel^  statusButtons;
        System::Windows::Forms::ToolStripStatusLabel^  statusXCoord;
        System::Windows::Forms::ToolStripStatusLabel^  statusYCoord;


    void InitializeComponent(void)
    {
            this->tsContainer =
                (gcnew System::Windows::Forms::ToolStripContainer());
            this->statusStrip1 =
                (gcnew System::Windows::Forms::StatusStrip());
            this->statusButtons =
                (gcnew System::Windows::Forms::ToolStripStatusLabel());
            this->statusXCoord =
                (gcnew System::Windows::Forms::ToolStripStatusLabel());
            this->statusYCoord =
                (gcnew System::Windows::Forms::ToolStripStatusLabel());
            this->tsContainer->BottomToolStripPanel->SuspendLayout();
            this->tsContainer->SuspendLayout();
            this->statusStrip1->SuspendLayout();
            this->SuspendLayout();
            //
            // tsContainer
            //
            //
            // tsContainer.BottomToolStripPanel
            //
            this->tsContainer->BottomToolStripPanel->Controls->Add(
                this->statusStrip1);
            //
            // tsContainer.ContentPanel
            //
            this->tsContainer->ContentPanel->Size =
                System::Drawing::Size(292, 251);
            this->tsContainer->ContentPanel->MouseDown +=
                gcnew System::Windows::Forms::MouseEventHandler(this,
                &Form1::tsContainer_ContentPanel_MouseDown);

            this->tsContainer->ContentPanel->MouseMove +=
                gcnew System::Windows::Forms::MouseEventHandler(this,
                &Form1::tsContainer1_ContentPanel_MouseMove);
            this->tsContainer->Dock = System::Windows::Forms::DockStyle::Fill;
            this->tsContainer->Location = System::Drawing::Point(0, 0);
            this->tsContainer->Name = L"tsContainer";
            this->tsContainer->Size = System::Drawing::Size(292, 273);
            this->tsContainer->TabIndex = 0;
            this->tsContainer->Text = L"toolStripContainer1";
            //
            // statusStrip1
            //
            this->statusStrip1->Dock = System::Windows::Forms::DockStyle::None;
            this->statusStrip1->Items->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(3)
                {this->statusButtons, this->statusXCoord, this->statusYCoord});
            this->statusStrip1->Location = System::Drawing::Point(0, 0);
            this->statusStrip1->Name = L"statusStrip1";
            this->statusStrip1->Size = System::Drawing::Size(292, 22);
            this->statusStrip1->TabIndex = 0;
            //
            // statusButtons
            //
            this->statusButtons->Name = L"statusButtons";
            this->statusButtons->Size = System::Drawing::Size(177, 17);
            this->statusButtons->Spring = true;
            this->statusButtons->TextAlign =
                System::Drawing::ContentAlignment::MiddleLeft;
            //
            // statusXCoord
            //
            this->statusXCoord->AutoSize = false;
            this->statusXCoord->BorderSides =
            static_cast<System::Windows::Forms::ToolStripStatusLabelBorderSides>
            ((((System::Windows::Forms::ToolStripStatusLabelBorderSides::Left
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Top)
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Right)
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Bottom));
            this->statusXCoord->BorderStyle =
                System::Windows::Forms::Border3DStyle::Sunken;
            this->statusXCoord->Name = L"statusXCoord";
            this->statusXCoord->Size = System::Drawing::Size(50, 17);
            //
            // statusYCoord
            //
            this->statusYCoord->AutoSize = false;
            this->statusYCoord->BorderSides =
            static_cast<System::Windows::Forms::ToolStripStatusLabelBorderSides>
            ((((System::Windows::Forms::ToolStripStatusLabelBorderSides::Left
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Top)
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Right)
            | System::Windows::Forms::ToolStripStatusLabelBorderSides::Bottom));

            this->statusYCoord->BorderStyle =
                System::Windows::Forms::Border3DStyle::Sunken;
            this->statusYCoord->Name = L"statusYCoord";
            this->statusYCoord->Size = System::Drawing::Size(50, 17);
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Controls->Add(this->tsContainer);
            this->Name = L"Form1";
            this->Text = L"Status Strip Mouse Tracking";
            this->tsContainer->BottomToolStripPanel->ResumeLayout(false);
            this->tsContainer->BottomToolStripPanel->PerformLayout();
            this->tsContainer->ResumeLayout(false);
            this->tsContainer->PerformLayout();
            this->statusStrip1->ResumeLayout(false);
            this->statusStrip1->PerformLayout();
            this->ResumeLayout(false);
    }
    
  private:
        System::Void tsContainer_ContentPanel_MouseDown(System::Object^ sender,
                                     System::Windows::Forms::MouseEventArgs^ e)
        {
           // clicked mouse button in first status bar panel
            if (e->Button == System::Windows::Forms::MouseButtons::Right)
                statusButtons->Text = "Right";
            else if (e->Button == System::Windows::Forms::MouseButtons::Left)
                statusButtons->Text = "Left";
            else
                statusButtons->Text = "Middle";
         }

        System::Void tsContainer1_ContentPanel_MouseMove(System::Object^ sender,
                                     System::Windows::Forms::MouseEventArgs^  e)
        {
             // x,y coords in second and third status bar panels
            statusXCoord->Text = String::Format("X={0}", e->X);
            statusYCoord->Text = String::Format("Y={0}", e->Y);
        }
  };



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

   

2 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(260, 36);
            this->bnSubmit->Margin = System::Windows::Forms::Padding(1,3,3,3);
            this->bnSubmit->Name = L"bnSubmit";
            this->bnSubmit->Size = System::Drawing::Size(56, 20);
            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(14, 232);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(56, 13);
            this->label3->TabIndex = 14;
            this->label3->Text = L"Password:";
            // 
            // tbPassword
            // 
            this->tbPassword->CausesValidation = false;
            this->tbPassword->Location = System::Drawing::Point(78, 226);
            this->tbPassword->MaxLength = 16;
            this->tbPassword->Name = L"tbPassword";
            this->tbPassword->PasswordChar = '?';
            this->tbPassword->Size = System::Drawing::Size(238, 20);
            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(14, 63);
            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(302, 156);
            this->tbOutput->TabIndex = 12;
            this->tbOutput->TabStop = false;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(168, 15);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(69, 13);
            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(168, 36);
            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(89, 20);
            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(14, 15);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(38, 13);
            this->label1->TabIndex = 9;
            this->label1->Text = L"Name:";
            // 
            // tbName
            // 
            this->tbName->Location = System::Drawing::Point(14, 36);
            this->tbName->Name = L"tbName";
            this->tbName->Size = System::Drawing::Size(147, 20);
            this->tbName->TabIndex = 7;
            this->tbName->Validating += 
                gcnew System::ComponentModel::CancelEventHandler(this, 
                                                   &Form1::tbName_Validating);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(331, 261);
            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;
}

3 TreeView Demo

 

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

        System::Windows::Forms::TreeView^  tView;
        System::Windows::Forms::ImageList^  imFolders;
        System::ComponentModel::IContainer^  components;

    void InitializeComponent(void)
    {
            this->components = (gcnew System::ComponentModel::Container());
            System::Windows::Forms::TreeNode^ treeNode1 =
                (gcnew System::Windows::Forms::TreeNode(L"<holder>"));
            System::Windows::Forms::TreeNode^ treeNode2 =
                (gcnew System::Windows::Forms::TreeNode(
                    L"Root Node A", 0, 1,
                    gcnew cli::array< System::Windows::Forms::TreeNode^ >(1)
                    {treeNode1}));
            System::Windows::Forms::TreeNode^ treeNode3 =
                (gcnew System::Windows::Forms::TreeNode(L"<holder>"));

            System::Windows::Forms::TreeNode^ treeNode4 =
                (gcnew System::Windows::Forms::TreeNode(
                    L"Root Node B", 0, 1,
                    gcnew cli::array< System::Windows::Forms::TreeNode^ >(1)
                    {treeNode3}));
            System::ComponentModel::ComponentResourceManager^ resources =
       (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
            this->tView = (gcnew System::Windows::Forms::TreeView());
            this->imFolders =
                (gcnew System::Windows::Forms::ImageList(this->components));
            this->SuspendLayout();
            //
            // tView
            //
            this->tView->Dock = System::Windows::Forms::DockStyle::Fill;
            this->tView->ImageIndex = 0;
            this->tView->ImageList = this->imFolders;
            this->tView->LabelEdit = true;
            this->tView->Location = System::Drawing::Point(0, 0);
            this->tView->Name = L"tView";
            treeNode1->Name = L"Node1";
            treeNode1->Text = L"<holder>";
            treeNode2->ImageIndex = 0;
            treeNode2->Name = L"Node0";
            treeNode2->SelectedImageIndex = 1;
            treeNode2->Text = L"Root Node A";
            treeNode3->Name = L"Node3";
            treeNode3->Text = L"<holder>";
            treeNode4->ImageIndex = 0;
            treeNode4->Name = L"Node2";
            treeNode4->SelectedImageIndex = 1;
            treeNode4->Text = L"Root Node B";
            this->tView->Nodes->AddRange(
                gcnew cli::array< System::Windows::Forms::TreeNode^ >(2)
                    {treeNode2, treeNode4});
            this->tView->SelectedImageIndex = 1;
            this->tView->Size = System::Drawing::Size(194, 481);
            this->tView->TabIndex = 0;
            this->tView->BeforeExpand +=
                gcnew System::Windows::Forms::TreeViewCancelEventHandler(this,
                                                  &Form1::tView_BeforeExpand);
            //
            // imFolders
            //
            this->imFolders->ImageStream =
                (cli::safe_cast<System::Windows::Forms::ImageListStreamer^ >
                (resources->GetObject(L"imFolders.ImageStream")));
            this->imFolders->Images->SetKeyName(0, L"CLSDFOLD.ICO");
            this->imFolders->Images->SetKeyName(1, L"OPENFOLD.ICO");
            //
            // Form1

            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(194, 481);
            this->Controls->Add(this->tView);
            this->Name = L"Form1";
            this->Text = L"Tree View Example";
            this->ResumeLayout(false);
    }

        System::Void tView_BeforeExpand(System::Object^ sender,
                            System::Windows::Forms::TreeViewCancelEventArgs^ e)
        {
            // Already expanded before?
            if (e->Node->Nodes->Count > 1)
                return;  // Already expanded
            else if (e->Node->Nodes->Count == 1)
            {
                if (e->Node->Nodes[0]->Text->Equals("<holder>"))
                    e->Node->Nodes->RemoveAt(0); // Node ready for expanding
                else
                    return; // Already expanded but only one sub node
            }
            // Randomly expand the node
            Random ^rand = gcnew Random();
            int rnd = rand->Next(1,5);
            for (int i = 0; i < rnd; i++) // Randon number of subnodes
            {
                TreeNode ^stn =
                    gcnew TreeNode(String::Format("Sub Node {0}", i+1), 0, 1);
                e->Node->Nodes->Add(stn);

                if (rand->Next(2) == 1)  // Has sub sub-nodes
                    stn->Nodes->Add(gcnew TreeNode("<holder>", 0, 1));
            }
        }
  };
}

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

4 CheckBox demo

 

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::CheckBox^  BottomCheck;
        System::Windows::Forms::CheckBox^  checkBox2;
        System::Windows::Forms::CheckBox^  checkBox1;
        System::Windows::Forms::CheckBox^  TopCheck;


    void InitializeComponent(void)
    {
            this->BottomCheck = (gcnew System::Windows::Forms::CheckBox());
            this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
            this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
            this->TopCheck = (gcnew System::Windows::Forms::CheckBox());
            this->SuspendLayout();
            // 
            // BottomCheck

            // 
            this->BottomCheck->AutoSize = true;
            this->BottomCheck->Enabled = false;
            this->BottomCheck->Location = System::Drawing::Point(52, 167);
            this->BottomCheck->Name = L"BottomCheck";
            this->BottomCheck->Size = System::Drawing::Size(127, 17);
            this->BottomCheck->TabIndex = 4;
            this->BottomCheck->TabStop = false;
            this->BottomCheck->Text = L"You Can\'t Check Me!";
            this->BottomCheck->Visible = false;
            this->BottomCheck->Enter += 
                gcnew System::EventHandler(this, &Form1::BottomCheck_Enter);
            this->BottomCheck->MouseEnter += 
                gcnew System::EventHandler(this, &Form1::BottomCheck_Enter);
            // 
            // checkBox2
            // 
            this->checkBox2->AutoSize = true;
            this->checkBox2->Location = System::Drawing::Point(52, 130);
            this->checkBox2->Name = L"checkBox2";
            this->checkBox2->Size = System::Drawing::Size(106, 17);
            this->checkBox2->TabIndex = 5;
            this->checkBox2->Text = L"Don\'t Forget ME!";
            // 
            // checkBox1
            // 
            this->checkBox1->AutoSize = true;
            this->checkBox1->Checked = true;
            this->checkBox1->CheckState = 
                System::Windows::Forms::CheckState::Indeterminate;
            this->checkBox1->Location = System::Drawing::Point(52, 90);
            this->checkBox1->Name = L"checkBox1";
            this->checkBox1->Size = System::Drawing::Size(133, 17);
            this->checkBox1->TabIndex = 2;
            this->checkBox1->Text = L"Check Me! Check Me!";
            this->checkBox1->ThreeState = true;
            // 
            // TopCheck
            // 
            this->TopCheck->AutoSize = true;
            this->TopCheck->Location = System::Drawing::Point(52, 49);
            this->TopCheck->Name = L"TopCheck";
            this->TopCheck->Size = System::Drawing::Size(127, 17);
            this->TopCheck->TabIndex = 3;
            this->TopCheck->TabStop = false;
            this->TopCheck->Text = L"You Can\'t Check Me!";
            this->TopCheck->Enter += 
                gcnew System::EventHandler(this, &Form1::TopCheck_Enter);
            this->TopCheck->MouseEnter += 
                gcnew System::EventHandler(this, &Form1::TopCheck_Enter);

            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(242, 273);
            this->Controls->Add(this->BottomCheck);
            this->Controls->Add(this->checkBox2);
            this->Controls->Add(this->checkBox1);
            this->Controls->Add(this->TopCheck);
            this->Name = L"Form1";
            this->Text = L"Can\'t Check Me";
            this->ResumeLayout(false);
            this->PerformLayout();
    }

    private: 
        System::Void TopCheck_Enter(System::Object^ sender, System::EventArgs^ e)
        {
            // Hide Top checkbox and display bottom
            TopCheck->Enabled = false; 
            TopCheck->Visible = false; 
            BottomCheck->Enabled = true; 
            BottomCheck->Visible = true; 
        }

    private: 
        System::Void BottomCheck_Enter(System::Object^  sender, System::EventArgs^  e)
        {
            // Hide Bottom checkbox and display top
            BottomCheck->Enabled = false; 
            BottomCheck->Visible = false; 
            TopCheck->Enabled = true; 
            TopCheck->Visible = true; 
        }
  };

5 Color Dialog 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:
    void InitializeComponent(void)
    {
            this->SuspendLayout();
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Name = L"Form1";
            this->Text = L"Common Color Dialog - Click Form";
            this->Click +=
                gcnew System::EventHandler(this, &Form1::Form1_Click);
            this->ResumeLayout(false);
    }
        System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e)
        {
            ColorDialog^ colordialog = gcnew ColorDialog();

            if (colordialog->ShowDialog() ==
                System::Windows::Forms::DialogResult::OK)
            {
                BackColor = colordialog->Color;
            }
        }
  };

 6 Custom Dialog

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

        System::Windows::Forms::Label^  lbRetString;
        System::Windows::Forms::Label^  lbRetVal;
    void InitializeComponent(void)
    {
            this->lbRetString = (gcnew System::Windows::Forms::Label());
            this->lbRetVal = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            //
            // lbRetString
            //
            this->lbRetString->Location = System::Drawing::Point(34, 119);
            this->lbRetString->Name = L"lbRetString";
            this->lbRetString->Size = System::Drawing::Size(225, 19);
            this->lbRetString->TabIndex = 3;
            //
            // lbRetVal
            //
            this->lbRetVal->Location = System::Drawing::Point(34, 77);
            this->lbRetVal->Name = L"lbRetVal";
            this->lbRetVal->Size = System::Drawing::Size(225, 19);
            this->lbRetVal->TabIndex = 2;
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Controls->Add(this->lbRetString);
            this->Controls->Add(this->lbRetVal);
            this->Name = L"Form1";
            this->Text = L"Click Form to get dialog";
            this->Click +=
                gcnew System::EventHandler(this, &Form1::Form1_Click);
            this->ResumeLayout(false);
    }
        System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e)
        {
            MyDialog ^mydialog = gcnew MyDialog();
            mydialog->PassedValue = "This has been passed from Form1";

            if (mydialog->ShowDialog() ==
                System::Windows::Forms::DialogResult::OK)
                lbRetVal->Text = "OK";
            else if (mydialog->DialogResult ==
                System::Windows::Forms::DialogResult::Abort)
                lbRetVal->Text = "Abort";
            else
                lbRetVal->Text = "Cancel";

            lbRetString->Text = mydialog->PassedValue;
        }
  };


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

    public:
        property String^ PassedValue  // PassedValue property
        {
            void set(String ^value)
            {
                tbPassedValue->Text = value;
            }
            String ^get()
            {
            return tbPassedValue->Text;
            }
        }

        System::Windows::Forms::Button^  bnCancel;
        System::Windows::Forms::Button^  bnAbort;
        System::Windows::Forms::Button^  bnOK;
        System::Windows::Forms::TextBox^  tbPassedValue;

    void InitializeComponent(void)
    {
            this->bnCancel = (gcnew System::Windows::Forms::Button());
            this->bnAbort = (gcnew System::Windows::Forms::Button());
            this->bnOK = (gcnew System::Windows::Forms::Button());
            this->tbPassedValue = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();

            //
            // bnCancel
            //
            this->bnCancel->DialogResult =
                System::Windows::Forms::DialogResult::Cancel;
            this->bnCancel->Location = System::Drawing::Point(205, 60);
            this->bnCancel->Name = L"bnCancel";
            this->bnCancel->Size = System::Drawing::Size(75, 23);
            this->bnCancel->TabIndex = 7;
            this->bnCancel->Text = L"Cancel";
            //
            // bnAbort
            //
            this->bnAbort->DialogResult =
                System::Windows::Forms::DialogResult::Abort;
            this->bnAbort->Location = System::Drawing::Point(110, 60);
            this->bnAbort->Name = L"bnAbort";
            this->bnAbort->Size = System::Drawing::Size(75, 23);
            this->bnAbort->TabIndex = 6;
            this->bnAbort->Text = L"Abort";
            //
            // bnOK
            //
            this->bnOK->DialogResult = System::Windows::Forms::DialogResult::OK;
            this->bnOK->Location = System::Drawing::Point(13, 60);
            this->bnOK->Name = L"bnOK";
            this->bnOK->Size = System::Drawing::Size(75, 23);
            this->bnOK->TabIndex = 5;
            this->bnOK->Text = L"OK";
            //
            // tbPassedValue
            //
            this->tbPassedValue->Location = System::Drawing::Point(13, 20);
            this->tbPassedValue->Name = L"tbPassedValue";
            this->tbPassedValue->Size = System::Drawing::Size(267, 20);
            this->tbPassedValue->TabIndex = 4;
            //
            // myDialog
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 102);
            this->Controls->Add(this->bnCancel);
            this->Controls->Add(this->bnAbort);
            this->Controls->Add(this->bnOK);
            this->Controls->Add(this->tbPassedValue);
            this->Name = L"myDialog";
            this->Text = L"My Custom Dialog";
            this->ResumeLayout(false);
            this->PerformLayout();
        }
  };

7 OnPaint

 
  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)
    {
            this->SuspendLayout();
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->Paint += 
                gcnew System::Windows::Forms::PaintEventHandler(this, 
                                                           &Form1::Form1_Paint);
            this->ResumeLayout(false);
    }
        virtual void OnPaint(System::Windows::Forms::PaintEventArgs ^e) override
        {
//          Form::OnPaint(e);

            e->Graphics->DrawString("Hello GDI+", 
               gcnew Drawing::Font("Arial", 16), Brushes::Black, 75.0, 110.0);

            Form::OnPaint(e);
        }
        System::Void Form1_Paint(System::Object^ sender,
                                 System::Windows::Forms::PaintEventArgs^ e)
        {
            e->Graphics->DrawString("Hello GDI+", 
                gcnew Drawing::Font("Arial", 16), Brushes::Purple, 75.0, 110.0);
        }
  };


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

8 subclass Form

[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::ComponentModel::Container ^components;

    void InitializeComponent(void)
    {
      this->SuspendLayout();
      // 
      // Form1
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->BackColor = System::Drawing::Color::Black;
      this->ClientSize = System::Drawing::Size(692, 276);
      this->Cursor = System::Windows::Forms::Cursors::UpArrow;
      this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
      this->Name = L"Form1";
      this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Show;
      this->Text = L"Custom Hello";
      this->TopMost = true;
      this->ResumeLayout(false);

    }
  };

9 List Transfers

 

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

        System::Windows::Forms::ListBox^  LBDest;
        System::Windows::Forms::Button^  bnR2L;
        System::Windows::Forms::Button^  bnL2R;
        System::Windows::Forms::ListBox^  LBOrg;
        System::Windows::Forms::Label^  label2;
        System::Windows::Forms::Label^  label1;

    void InitializeComponent(void)
    {
            this->LBDest = (gcnew System::Windows::Forms::ListBox());
            this->bnR2L = (gcnew System::Windows::Forms::Button());
            this->bnL2R = (gcnew System::Windows::Forms::Button());
            this->LBOrg = (gcnew System::Windows::Forms::ListBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // LBDest
            // 
            this->LBDest->FormattingEnabled = true;
            this->LBDest->Location = System::Drawing::Point(213, 46);
            this->LBDest->Name = L"LBDest";
            this->LBDest->SelectionMode = 
                System::Windows::Forms::SelectionMode::MultiSimple;
            this->LBDest->Size = System::Drawing::Size(134, 134);
            this->LBDest->TabIndex = 10;
            this->LBDest->DoubleClick += 
                gcnew System::EventHandler(this, &Form1::LBDest_DoubleClick);
            // 
            // bnR2L
            // 
            this->bnR2L->Location = System::Drawing::Point(167, 108);
            this->bnR2L->Name = L"bnR2L";
            this->bnR2L->Size = System::Drawing::Size(33, 20);
            this->bnR2L->TabIndex = 9;
            this->bnR2L->Text = L"<==";
            this->bnR2L->Click += 
                gcnew System::EventHandler(this, &Form1::bnR2L_Click);
            // 
            // bnL2R
            // 
            this->bnL2R->Location = System::Drawing::Point(167, 80);
            this->bnL2R->Name = L"bnL2R";
            this->bnL2R->Size = System::Drawing::Size(33, 20);
            this->bnL2R->TabIndex = 8;
            this->bnL2R->Text = L"==>";
            this->bnL2R->Click += 
                gcnew System::EventHandler(this, &Form1::bnL2R_Click);
            // 
            // LBOrg
            // 
            this->LBOrg->FormattingEnabled = true;
            this->LBOrg->Items->AddRange(gcnew cli::array< System::Object^>(10)
                {L"System", L"System::Collections", L"System::Data", 
                 L"System::Drawing", L"System::IO", L"System::Net", 
                 L"System::Threading", L"System::Web", 
                 L"System::Windows::Forms", L"System::Xml"});

            this->LBOrg->Location = System::Drawing::Point(20, 46);
            this->LBOrg->Name = L"LBOrg";
            this->LBOrg->SelectionMode = 
                System::Windows::Forms::SelectionMode::MultiExtended;
            this->LBOrg->Size = System::Drawing::Size(133, 134);
            this->LBOrg->Sorted = true;
            this->LBOrg->TabIndex = 6;
            this->LBOrg->DoubleClick += 
                gcnew System::EventHandler(this, &Form1::LBOrg_DoubleClick);
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(213, 17);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(104, 13);
            this->label2->TabIndex = 7;
            this->label2->Text = L"Unsorted Multisimple";
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(20, 17);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(107, 13);
            this->label1->TabIndex = 5;
            this->label1->Text = L"Sorted Multiextended";
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(367, 196);
            this->Controls->Add(this->LBDest);
            this->Controls->Add(this->bnR2L);
            this->Controls->Add(this->bnL2R);
            this->Controls->Add(this->LBOrg);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label1);
            this->Name = L"Form1";
            this->Text = L"List Box Transfers";
            this->ResumeLayout(false);
            this->PerformLayout();
    }
        System::Void LBOrg_DoubleClick(System::Object^ sender, 
                                       System::EventArgs^ e)
        {
            if (LBOrg->SelectedItem != nullptr)
            {
                LBDest->Items->Add(LBOrg->SelectedItem); 
                LBOrg->Items->Remove(LBOrg->SelectedItem); 
            }
        }

        System::Void LBDest_DoubleClick(System::Object^ sender, 
                                        System::EventArgs^ e)
        {
            if (LBDest->SelectedItem != nullptr)
            {
                LBOrg->Items->Add(LBDest->SelectedItem); 
                LBDest->Items->Remove(LBDest->SelectedItem); 
            }
        }

        System::Void bnL2R_Click(System::Object^ sender, System::EventArgs^ e)
        {
            array<Object^>^ tmp = 
                gcnew array<Object^>(LBOrg->SelectedItems->Count); 
            LBOrg->SelectedItems->CopyTo(tmp, 0); 
            LBDest->Items->AddRange(tmp); 
            for (int i = 0; i < tmp->Length; i++) 
                LBOrg->Items->Remove(tmp[i]); 
        }

        System::Void bnR2L_Click(System::Object^ sender, System::EventArgs^ e)
        {
            array<Object^>^ tmp = 
                gcnew array<Object^>(LBDest->SelectedItems->Count);
            LBDest->SelectedItems->CopyTo(tmp, 0); 
            LBOrg->Items->AddRange(tmp); 
            for (int i = 0; i < tmp->Length; i++) 
                LBDest->Items->Remove(tmp[i]); 
       }
  };



[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
  // Enabling Windows XP visual effects before any controls are created
  Application::EnableVisualStyles();
  Application::SetCompatibleTextRenderingDefault(false); 

  // Create the main window and run it
  Application::Run(gcnew Form1());
  return 0;
}

10 Display string on MessageBox

 
#include "stdafx.h"
#using "System.Windows.Forms.dll"

using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Windows::Forms;

int main()
{
   StringWriter^ sw = gcnew StringWriter();
   sw->WriteLine("asdf");
   sw->Write("asdf\n");
   sw->WriteLine();

   String^ jambo = "asdf";
   String^ s = String::Format("{0}, {1}.", jambo, jambo);
   sw->WriteLine(s);
   sw->Write("Make a wish, {0}, {0}.", jambo);
   s = "asdf.\n";
   String::Concat(s, "asdf?");
   sw->WriteLine(s);


   StringBuilder^ sb = gcnew StringBuilder();
   sb->Append("asdf\n");
   sw->WriteLine(sb);

   // The resulting string might be displayed to the user in a GUI
   MessageBox::Show(sw->ToString(), "Poetry", MessageBoxButtons::OK);
}