C++ Visual.net : GUI Form ex 1

1 Many Buttons

 
  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::Button^  TooMany;

    void InitializeComponent(void)
    {
            this->TooMany = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // TooMany
            // 
            this->TooMany->Location = System::Drawing::Point(12, 12);
            this->TooMany->Name = L"TooMany";
            this->TooMany->Size = System::Drawing::Size(75, 23);
            this->TooMany->TabIndex = 1;
            this->TooMany->Text = L"Click Me!";
            this->TooMany->Click += 
                gcnew System::EventHandler(this, &Form1::TooMany_Click);

            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->AutoScroll = true;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Controls->Add(this->TooMany);
            this->Name = L"Form1";
            this->Text = L"Too Many Buttons";
            this->ResumeLayout(false);
    }

        System::Void TooMany_Click(System::Object^ sender, 
                                   System::EventArgs^ e)
        {
            // Grab the location of the button that was clicked
            Point p = ((Button^)sender)->Location; 

            // Create a dynamic button
            Button ^Many = gcnew Button(); 
            Many->Location = Drawing::Point(p.X + 36, p.Y + 26); 
            Many->Text = L"Click Me!"; 
            Many->Click += gcnew System::EventHandler(this, 
                                                      &Form1::TooMany_Click); 
            // Add dynamic button to Form
            Controls->Add(Many); 
        }
  };


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

2 ListBox and CheckBoxListBox

 

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

            array<Object^>^ Items = gcnew array<Object^> { 
                "Appleman", "Challa",    "Chand",    "Cornell",
                "Fraser",   "Gunnerson", "Harris",   "Rammer", 
                "Symmonds", "Thomsen",   "Troelsen", "Vaughn" 
            };

            clBox->Items->AddRange(Items);
            lBox->Items->AddRange(Items);

            cBox = gcnew array<CheckBox^>(Items->Length); 
            
            int j = cBox->Length/2;
            for (int i = 0; i < j; i++)
            {
                // Build Left Column
                cBox[i] = gcnew CheckBox();
                cBox[i]->Location = Drawing::Point(50, 160+(30*i)); 
                cBox[i]->TabIndex = i+2; 
                cBox[i]->Text = Items[i]->ToString(); 
                cBox[i]->CheckStateChanged += 
                    gcnew EventHandler(this, &Form1::cBox_CheckStateChanged); 
                
                // Build Right Column
                cBox[i+j] = gcnew CheckBox();
                cBox[i+j]->Location = Drawing::Point(180, 160+(30*i)); 
                cBox[i+j]->TabIndex = i+j+2; 
                cBox[i+j]->Text = Items[i+j]->ToString(); 
                cBox[i+j]->CheckStateChanged += 
                    gcnew EventHandler(this, &Form1::cBox_CheckStateChanged); 
            }
            // Add all CheckBoxes to Form
            Controls->AddRange(cBox);
  }
  private:
        System::Windows::Forms::ListBox^  lBox;
        System::Windows::Forms::CheckedListBox^  clBox;

        array<CheckBox^>^ cBox; 

    void InitializeComponent(void)
    {
      this->lBox = (gcnew System::Windows::Forms::ListBox());
      this->clBox = (gcnew System::Windows::Forms::CheckedListBox());
      this->SuspendLayout();
      // 
      // lBox
      // 
      this->lBox->FormattingEnabled = true;
      this->lBox->Location = System::Drawing::Point(356, 32);
      this->lBox->Name = L"lBox";
      this->lBox->Size = System::Drawing::Size(120, 264);
      this->lBox->TabIndex = 3;
      this->lBox->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::lBox_SelectedIndexChanged);
      // 
      // clBox
      // 
      this->clBox->FormattingEnabled = true;
      this->clBox->Location = System::Drawing::Point(12, 32);
      this->clBox->MultiColumn = true;
      this->clBox->Name = L"clBox";
      this->clBox->Size = System::Drawing::Size(323, 79);
      this->clBox->TabIndex = 2;
      this->clBox->ThreeDCheckBoxes = true;
      this->clBox->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::clBox_SelectedIndexChanged);
      this->clBox->ItemCheck += gcnew System::Windows::Forms::ItemCheckEventHandler(this, &Form1::clBox_ItemCheck);
      // 
      // Form1
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->ClientSize = System::Drawing::Size(494, 392);
      this->Controls->Add(this->lBox);
      this->Controls->Add(this->clBox);
      this->Name = L"Form1";
      this->Text = L"Splitting The Check List Box";
      this->ResumeLayout(false);

    }
            System::Void clBox_ItemCheck(System::Object^ sender, 
                                 System::Windows::Forms::ItemCheckEventArgs^ e)
        {
         // update state of CheckBox with same index as checked CheckedListBox
            cBox[e->Index]->CheckState = e->NewValue; 
        }

        System::Void clBox_SelectedIndexChanged(System::Object^ sender, 
                                                System::EventArgs^ e)
        {
         // update ListBox with same selected item in the CheckedListBox
            lBox->SelectedItem = clBox->SelectedItem->ToString(); 
        }

        System::Void lBox_SelectedIndexChanged(System::Object^ sender, 
                                               System::EventArgs^ e)
        {
         // update CheckedListBox with same selected item in the ListBox
            clBox->SelectedItem = lBox->SelectedItem; 
        }

        void cBox_CheckStateChanged(Object^ sender, EventArgs^ e) 
        {
         // update state of CheckedListBox with same index as checked CheckBox
            CheckBox^ cb = (CheckBox^)sender;
            clBox->SetItemCheckState(Array::IndexOf(cBox, cb), cb->CheckState);
        }
  };

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

}

3 Sync ComboBox

 

  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();
            PopulateLists();
    }
        System::Windows::Forms::ComboBox^  ddlist;
        System::Windows::Forms::ComboBox^  simple;
        System::Windows::Forms::ComboBox^  ddown;

    void InitializeComponent(void)
    {
            this->ddlist = (gcnew System::Windows::Forms::ComboBox());
            this->simple = (gcnew System::Windows::Forms::ComboBox());
            this->ddown = (gcnew System::Windows::Forms::ComboBox());
            this->SuspendLayout();
            // 
            // ddlist
            // 
            this->ddlist->DropDownStyle = 
                System::Windows::Forms::ComboBoxStyle::DropDownList;
            this->ddlist->FormattingEnabled = true;
            this->ddlist->Location = System::Drawing::Point(300, 14);
            this->ddlist->Name = L"ddlist";
            this->ddlist->Size = System::Drawing::Size(121, 21);
            this->ddlist->TabIndex = 5;
            this->ddlist->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::ddlist_Change);
            // 
            // simple
            // 
            this->simple->DropDownStyle = 
                System::Windows::Forms::ComboBoxStyle::Simple;
            this->simple->FormattingEnabled = true;
            this->simple->Location = System::Drawing::Point(154, 11);
            this->simple->Name = L"simple";
            this->simple->Size = System::Drawing::Size(122, 117);
            this->simple->TabIndex = 4;
            this->simple->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::simple_Change);
            this->simple->TextChanged += 
                gcnew System::EventHandler(this, &Form1::simple_Change);
            // 
            // ddown
            // 
            this->ddown->FormattingEnabled = true;
            this->ddown->Location = System::Drawing::Point(12, 14);
            this->ddown->MaxDropDownItems = 3;
            this->ddown->MaxLength = 10;
            this->ddown->Name = L"ddown";
            this->ddown->Size = System::Drawing::Size(121, 21);
            this->ddown->TabIndex = 3;
            this->ddown->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::ddown_Change);

            this->ddown->TextChanged += 
                gcnew System::EventHandler(this, &Form1::ddown_Change);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(433, 138);
            this->Controls->Add(this->ddlist);
            this->Controls->Add(this->simple);
            this->Controls->Add(this->ddown);
            this->Name = L"Form1";
            this->Text = L"Synchronized Combo boxing";
            this->ResumeLayout(false);
    }

        void PopulateLists()
        {
            // Item to be placed in all ComboBoxes
            array<Object^>^ ddItems = gcnew array<Object^> { 
                L"oranges", L"cherries", L"apples",
                L"lemons",  L"bananas",  L"grapes" 
            };
            ddown->Items->AddRange(ddItems);        
            simple->Items->AddRange(ddItems);        
            ddlist->Items->AddRange(ddItems);
        }

        System::Void ddown_Change(System::Object^ sender, System::EventArgs^ e)
        {
            // Update simple and dropdownlist with dropdown text
            simple->Text = ddown->Text; 
            ddlist->SelectedItem = ddown->Text; 
        }

        System::Void simple_Change(System::Object^ sender,System::EventArgs^ e)
        {
            // Update dropdown and dropdownlist with simple text
            ddown->Text = simple->Text; 
            ddlist->SelectedItem = simple->Text; 
        }

        System::Void ddlist_Change(System::Object^ sender,System::EventArgs^ e)
        {
            // Update simple and dropdown with dropdownlist SelectedText
            ddown->SelectedItem = ddlist->SelectedItem; 
            simple->SelectedItem = ddlist->SelectedItem; 
        }
  };

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

}

4 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(103, 83);
            this->tbPword->Name = L"tbPword";
            this->tbPword->PasswordChar = '*';
            this->tbPword->Size = System::Drawing::Size(100, 20);
            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(34, 83);
            this->lbPword->Name = L"lbPword";
            this->lbPword->Size = System::Drawing::Size(53, 13);
            this->lbPword->TabIndex = 8;
            this->lbPword->Text = L"&Password";
            //
            // bnLogin
            //
            this->bnLogin->Location = System::Drawing::Point(75, 131);
            this->bnLogin->Name = L"bnLogin";
            this->bnLogin->Size = System::Drawing::Size(75, 23);
            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(103, 31);
            this->tbName->Name = L"tbName";
            this->tbName->Size = System::Drawing::Size(100, 20);
            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(34, 31);
            this->lbName->Name = L"lbName";
            this->lbName->Size = System::Drawing::Size(35, 13);
            this->lbName->TabIndex = 5;
            this->lbName->Text = L"&Name";

            //
            // eProvider
            //
            this->eProvider->ContainerControl = this;
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(237, 185);
            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, "");
        }
  }; 

} 

5 Mighty Label

 

  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)
    {
            labelSwitch = true;
      InitializeComponent();
    }

        System::Windows::Forms::Label^  MightyLabel;
        bool labelSwitch;

    void InitializeComponent(void)
    {
      this->MightyLabel = (gcnew System::Windows::Forms::Label());
      this->SuspendLayout();
      // 
      // MightyLabel
      // 
      this->MightyLabel->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->MightyLabel->Cursor = System::Windows::Forms::Cursors::Hand;
      this->MightyLabel->Location = System::Drawing::Point(63, 91);
      this->MightyLabel->Name = L"MightyLabel";
      this->MightyLabel->Size = System::Drawing::Size(150, 35);
      this->MightyLabel->TabIndex = 1;
      this->MightyLabel->Text = L"This is the mighty label! It will change when you click it";
      this->MightyLabel->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
      this->MightyLabel->Click += gcnew System::EventHandler(this, &Form1::MightyLabel_Click);
      // 
      // 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->MightyLabel);
      this->Name = L"Form1";
      this->Text = L"The Mighty Label";
      this->Click += gcnew System::EventHandler(this, &Form1::MightyLabel_Click);
      this->ResumeLayout(false);

    }
  private: System::Void MightyLabel_Click(System::Object^  sender, System::EventArgs^  e) 
    {
            if (labelSwitch) 
                MightyLabel->Text = L"Ouchie!!!  That hurt."; 
            else 
                MightyLabel->Text = L"Ooo!!!  That tickled."; 
            labelSwitch = !labelSwitch; 
    }
  };



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

6 Simple Menu 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^  toolStripContainer1;
        System::Windows::Forms::MenuStrip^  mainMenuStrip;
        System::Windows::Forms::ToolStripMenuItem^  miFile;
        System::Windows::Forms::ToolStripMenuItem^  miFileSub;
        System::Windows::Forms::ToolStripComboBox^  miFileSubThis;
        System::Windows::Forms::ToolStripMenuItem^  miFileExit;
        System::Windows::Forms::ToolStripMenuItem^  miFileSubCheck;
        System::Windows::Forms::ToolStripMenuItem^  miFileSubImage;
        System::Windows::Forms::ToolStripMenuItem^  miFileSubSayBoo;
        System::Windows::Forms::ToolStripMenuItem^  miHelp;
        System::Windows::Forms::ToolStripMenuItem^  miHelpAbout;
        System::Windows::Forms::ToolStripSeparator^  miFileSep1;
    void InitializeComponent(void)
    {
            System::ComponentModel::ComponentResourceManager^ resources =
       (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
            this->toolStripContainer1 =
                (gcnew System::Windows::Forms::ToolStripContainer());
            this->mainMenuStrip = (gcnew System::Windows::Forms::MenuStrip());
            this->miFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miFileSub =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miFileSubThis =
                (gcnew System::Windows::Forms::ToolStripComboBox());
            this->miFileSubCheck =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miFileSubImage =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miFileSubSayBoo =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miFileSep1 =
                (gcnew System::Windows::Forms::ToolStripSeparator());
            this->miFileExit =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miHelp =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->miHelpAbout =
                (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->toolStripContainer1->TopToolStripPanel->SuspendLayout();

            this->toolStripContainer1->SuspendLayout();
            this->mainMenuStrip->SuspendLayout();
            this->SuspendLayout();
            //
            // toolStripContainer1
            //
            // toolStripContainer1.ContentPanel
            //
            this->toolStripContainer1->ContentPanel->Size =
                System::Drawing::Size(292, 249);
            this->toolStripContainer1->Dock =
                System::Windows::Forms::DockStyle::Fill;
            this->toolStripContainer1->Location = System::Drawing::Point(0, 0);
            this->toolStripContainer1->Name = L"toolStripContainer1";
            this->toolStripContainer1->Size = System::Drawing::Size(292, 273);
            this->toolStripContainer1->TabIndex = 0;
            this->toolStripContainer1->Text = L"toolStripContainer1";
            //
            // toolStripContainer1.TopToolStripPanel
            //
            this->toolStripContainer1->TopToolStripPanel->Controls->Add(
                this->mainMenuStrip);
            //
            // mainMenuStrip
            //
            this->mainMenuStrip->Dock =System::Windows::Forms::DockStyle::None;
            this->mainMenuStrip->Items->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(2)
                {this->miFile, this->miHelp});
            this->mainMenuStrip->Location = System::Drawing::Point(0, 0);
            this->mainMenuStrip->Name = L"mainMenuStrip";
            this->mainMenuStrip->Size = System::Drawing::Size(292, 24);
            this->mainMenuStrip->TabIndex = 0;
            this->mainMenuStrip->Text = L"menuStrip1";
            //
            // miFile
            //
            this->miFile->DropDownItems->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(3)
                {this->miFileSub, this->miFileSep1, this->miFileExit});
            this->miFile->Name = L"miFile";
            this->miFile->Size = System::Drawing::Size(35, 20);
            this->miFile->Text = L"&File";
            //
            // miFileSub
            //
            this->miFileSub->DropDownItems->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(4)
                {this->miFileSubThis, this->miFileSubCheck,
                 this->miFileSubImage, this->miFileSubSayBoo});
            this->miFileSub->Name = L"miFileSub";
            this->miFileSub->Size = System::Drawing::Size(152, 22);
            this->miFileSub->Text = L"&Sub";
            //
            // miFileSubThis
            //
            this->miFileSubThis->Items->AddRange(
                gcnew cli::array< System::Object^>(3)
                {L"This", L"That", L"Other Thing"});
            this->miFileSubThis->Name = L"miFileSubThis";
            this->miFileSubThis->Size = System::Drawing::Size(121, 21);
            //
            // miFileSubCheck
            //
            this->miFileSubCheck->Checked = true;
            this->miFileSubCheck->CheckOnClick = true;
            this->miFileSubCheck->CheckState =
                System::Windows::Forms::CheckState::Checked;
            this->miFileSubCheck->Name = L"miFileSubCheck";
            this->miFileSubCheck->Size = System::Drawing::Size(181, 22);
            this->miFileSubCheck->Text = L"Check Me";
            //
            // miFileSubImage
            //
            this->miFileSubImage->Image =
                (cli::safe_cast<System::Drawing::Image^>
                (resources->GetObject(L"miFileSubImage.Image")));
            this->miFileSubImage->Name = L"miFileSubImage";
            this->miFileSubImage->Size = System::Drawing::Size(181, 22);
            this->miFileSubImage->Text = L"I have an image";
            //
            // miFileSubSayBoo
            //
            this->miFileSubSayBoo->Name = L"miFileSubSayBoo";
            this->miFileSubSayBoo->ShortcutKeys =
                static_cast<System::Windows::Forms::Keys>
                ((System::Windows::Forms::Keys::Control |
                  System::Windows::Forms::Keys::S));
            this->miFileSubSayBoo->Size = System::Drawing::Size(181, 22);
            this->miFileSubSayBoo->Text = L"Say Boo";
            this->miFileSubSayBoo->Click +=
                gcnew System::EventHandler(this,&Form1::miFileSubSayBoo_Click);
            //
            // miFileSep1
            //
            this->miFileSep1->Name = L"miFileSep1";
            this->miFileSep1->Size = System::Drawing::Size(149, 6);
            //
            // miFileExit
            //
            this->miFileExit->Name = L"miFileExit";
            this->miFileExit->Size = System::Drawing::Size(152, 22);
            this->miFileExit->Text = L"E&xit";
            this->miFileExit->Click +=
                gcnew System::EventHandler(this, &Form1::miFileExit_Click);
            //
            // miHelp
            //
            this->miHelp->DropDownItems->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(1)
                {this->miHelpAbout});
            this->miHelp->Name = L"miHelp";
            this->miHelp->Size = System::Drawing::Size(40, 20);
            this->miHelp->Text = L"&Help";
            //
            // miHelpAbout
            //
            this->miHelpAbout->Name = L"miHelpAbout";
            this->miHelpAbout->Size = System::Drawing::Size(152, 22);
            this->miHelpAbout->Text = L"About";
            this->miHelpAbout->Click +=
                gcnew System::EventHandler(this, &Form1::miHelpAbout_Click);
            //
            // 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->toolStripContainer1);
            this->MainMenuStrip = this->mainMenuStrip;
            this->Name = L"Form1";
            this->Text = L"Simple Menu";
            this->toolStripContainer1->TopToolStripPanel->ResumeLayout(false);
            this->toolStripContainer1->TopToolStripPanel->PerformLayout();
            this->toolStripContainer1->ResumeLayout(false);
            this->toolStripContainer1->PerformLayout();
            this->mainMenuStrip->ResumeLayout(false);
            this->mainMenuStrip->PerformLayout();
            this->ResumeLayout(false);
    }
        System::Void miFileExit_Click(System::Object^ sender, System::EventArgs^ e)
        {
             Application::Exit();
        }

        System::Void miHelpAbout_Click(System::Object^ sender, System::EventArgs^ e)
        {
            MessageBox::Show("Simple Menu v.1.0.0.0");
        }

        System::Void miFileSubSayBoo_Click(System::Object^ sender, System::EventArgs^ e)
        {
            MessageBox::Show("BOO");
        }
  };


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

7 Month Calendar 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();
    }
  private:
        System::Windows::Forms::Label^  End;
        System::Windows::Forms::Label^  Start;
        System::Windows::Forms::MonthCalendar^  monthCal;

    void InitializeComponent(void)
    {
      this->End = (gcnew System::Windows::Forms::Label());
      this->Start = (gcnew System::Windows::Forms::Label());
      this->monthCal = (gcnew System::Windows::Forms::MonthCalendar());
      this->SuspendLayout();
      // 
      // End
      // 
      this->End->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->End->Location = System::Drawing::Point(230, 323);
      this->End->Name = L"End";
      this->End->Size = System::Drawing::Size(83, 20);
      this->End->TabIndex = 5;
      // 
      // Start
      // 
      this->Start->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->Start->Location = System::Drawing::Point(122, 323);
      this->Start->Name = L"Start";
      this->Start->Size = System::Drawing::Size(83, 20);
      this->Start->TabIndex = 4;
      // 
      // monthCal
      // 
      this->monthCal->AnnuallyBoldedDates = gcnew cli::array< System::DateTime >(1) {System::DateTime(2007, 7, 4, 0, 0, 0, 0)};
      this->monthCal->CalendarDimensions = System::Drawing::Size(2, 2);
      this->monthCal->Location = System::Drawing::Point(1, 1);
      this->monthCal->MaxSelectionCount = 365;
      this->monthCal->MonthlyBoldedDates = gcnew cli::array< System::DateTime >(2) {System::DateTime(2007, 10, 1, 0, 0, 0, 0), System::DateTime(2007, 
        10, 15, 0, 0, 0, 0)};
      this->monthCal->Name = L"monthCal";
      this->monthCal->ShowWeekNumbers = true;
      this->monthCal->TabIndex = 3;
      this->monthCal->DateChanged += gcnew System::Windows::Forms::DateRangeEventHandler(this, &Form1::monthCal_DateChanged);
      // 
      // Form1
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->ClientSize = System::Drawing::Size(443, 346);
      this->Controls->Add(this->End);
      this->Controls->Add(this->Start);
      this->Controls->Add(this->monthCal);
      this->Name = L"Form1";
      this->Text = L"Month Calendar";
      this->ResumeLayout(false);

    }
        System::Void monthCal_DateChanged(System::Object^ sender,
                                 System::Windows::Forms::DateRangeEventArgs^ e)
        {
            // Update start and end range labels when date changes
            Start->Text = e->Start.Date.ToShortDateString();
            End->Text   = e->End.Date.ToShortDateString();
        }
  };



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

8  NotifyIcon 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::Button^  bnTaskBar;
        System::Windows::Forms::Button^  bnNotify;
        System::Windows::Forms::NotifyIcon^  notifyIcon;
        System::Windows::Forms::ContextMenuStrip^  menuExit;
        System::Windows::Forms::ToolStripMenuItem^  miExit;
  
    void InitializeComponent(void)
    {
            System::ComponentModel::ComponentResourceManager^ resources =
       (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
            this->bnTaskBar = (gcnew System::Windows::Forms::Button());
            this->bnNotify = (gcnew System::Windows::Forms::Button());
            this->notifyIcon =
                (gcnew System::Windows::Forms::NotifyIcon());
            this->menuExit =
            (gcnew System::Windows::Forms::ContextMenuStrip());
            this->miExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->menuExit->SuspendLayout();
            this->SuspendLayout();

            //
            // bnTaskBar
            //
            this->bnTaskBar->Location = System::Drawing::Point(28, 59);
            this->bnTaskBar->Name = L"bnTaskBar";
            this->bnTaskBar->Size = System::Drawing::Size(131, 23);
            this->bnTaskBar->TabIndex = 3;
            this->bnTaskBar->Text = L"Toggle TaskBar Icon";
            this->bnTaskBar->Click +=
                gcnew System::EventHandler(this, &Form1::bnTaskBar_Click);
            //
            // bnNotify
            //
            this->bnNotify->Location = System::Drawing::Point(28, 12);
            this->bnNotify->Name = L"bnNotify";
            this->bnNotify->Size = System::Drawing::Size(131, 23);
            this->bnNotify->TabIndex = 2;
            this->bnNotify->Text = L"Toggle Notify Icon";
            this->bnNotify->Click +=
                gcnew System::EventHandler(this, &Form1::bnNotify_Click);
            //
            // notifyIcon
            //
            this->notifyIcon->ContextMenuStrip = this->menuExit;
            this->notifyIcon->Icon = (cli::safe_cast<System::Drawing::Icon^>
                (resources->GetObject(L"notifyIcon.Icon")));
            this->notifyIcon->Text = L"Notify Icon Example";
            this->notifyIcon->Visible = true;
            //
            // menuExit
            //
            this->menuExit->Items->AddRange(
                gcnew cli::array< System::Windows::Forms::ToolStripItem^>(1)
                {this->miExit});
            this->menuExit->Name = L"miExit";
            this->menuExit->RightToLeft =
                System::Windows::Forms::RightToLeft::No;
            this->menuExit->Size = System::Drawing::Size(153, 48);
            //
            // miExit
            //
            this->miExit->Name = L"miExit";
            this->miExit->Size = System::Drawing::Size(152, 22);
            this->miExit->Text = L"E&xit";
            this->miExit->Click +=
                gcnew System::EventHandler(this, &Form1::miExit_Click);
            //
            // Form1
            //

            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(192, 106);
            this->Controls->Add(this->bnTaskBar);
            this->Controls->Add(this->bnNotify);
            this->Icon = (cli::safe_cast<System::Drawing::Icon^>
                (resources->GetObject(L"$this.Icon")));
            this->Name = L"Form1";
            this->Text = L"Notify Icon";
            this->menuExit->ResumeLayout(false);
            this->ResumeLayout(false);
    }
    private:
        System::Void bnNotify_Click(System::Object^ sender,
                                    System::EventArgs^ e)
        {
            notifyIcon->Visible = !notifyIcon->Visible;
        }

        System::Void bnTaskBar_Click(System::Object^ sender,
                                     System::EventArgs^ e)
        {
            this->ShowInTaskbar = ! this->ShowInTaskbar;
        }

        System::Void miExit_Click(System::Object^ sender,
                                  System::EventArgs^  e)
        {
            Application::Exit();
        }
  };
}

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

9 PictureBox 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();
    }
  private: System::Windows::Forms::PictureBox^  pictureBox1;
    void InitializeComponent(void)
    {
      System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
      this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
      (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
      this->SuspendLayout();
      // 
      // pictureBox1
      // 
      this->pictureBox1->Dock = System::Windows::Forms::DockStyle::Fill;
      this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.Image")));
      this->pictureBox1->Location = System::Drawing::Point(0, 0);
      this->pictureBox1->Name = L"pictureBox1";
      this->pictureBox1->Size = System::Drawing::Size(191, 277);
      this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
      this->pictureBox1->TabIndex = 0;
      this->pictureBox1->TabStop = false;
      // 
      // Form1
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
      this->ClientSize = System::Drawing::Size(191, 277);
      this->Controls->Add(this->pictureBox1);
      this->Name = L"Form1";
      this->Text = L"Shaina Shoshana";
      (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
      this->ResumeLayout(false);

    }
  };

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

10 Rich Text area 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();
            BuildLabels();
    }

  private:
        System::Windows::Forms::RichTextBox^  rtBox;

        array<System::Windows::Forms::Label^>^ labels; 

    void InitializeComponent(void)
    {
            this->rtBox = (gcnew System::Windows::Forms::RichTextBox());
            this->SuspendLayout();
            // 
            // rtBox
            // 
            this->rtBox->Anchor = 
                static_cast<System::Windows::Forms::AnchorStyles>
                ((((System::Windows::Forms::AnchorStyles::Top 
                | System::Windows::Forms::AnchorStyles::Bottom) 
                | System::Windows::Forms::AnchorStyles::Left) 
                | System::Windows::Forms::AnchorStyles::Right));
            this->rtBox->Location = System::Drawing::Point(0, 32);
            this->rtBox->Name = L"rtBox";
            this->rtBox->RightMargin = 900;
            this->rtBox->ScrollBars = 
                System::Windows::Forms::RichTextBoxScrollBars::ForcedVertical;
            this->rtBox->ShowSelectionMargin = true;
            this->rtBox->Size = System::Drawing::Size(950, 488);
            this->rtBox->TabIndex = 1;
            this->rtBox->Text = L"";
            this->rtBox->KeyDown += 
                gcnew System::Windows::Forms::KeyEventHandler(this, 
                                                       &Form1::rtBox_KeyDown);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(950, 520);
            this->Controls->Add(this->rtBox);
            this->Name = L"Form1";
            this->Text = L"(Very Simple Rich Text Editor)";
            this->ResumeLayout(false);
    }

        void BuildLabels()
        {
            array<String^>^ rtLabel = gcnew array<String^> {
                L"F1-Bold",   L"F2-Italics", L"F3-Underline",
                L"F4-Normal", L"F5-Red",     L"F6-Blue",
                L"F7-Green",  L"F8-Black",   L"F9-Load",    
                L"F10-Save"
            };
            labels = gcnew array<System::Windows::Forms::Label^>(10);


            // Build the labels
            for (int i = 0; i < labels->Length; i++)
            {
                labels[i] = gcnew Label();
                labels[i]->BackColor = SystemColors::ControlDark; 
                labels[i]->BorderStyle = BorderStyle::FixedSingle; 
                labels[i]->Location = Drawing::Point(5+(95*i), 8); 
                labels[i]->Size = Drawing::Size(85, 16); 
                labels[i]->Text = rtLabel[i]; 
                labels[i]->TextAlign = ContentAlignment::MiddleCenter; 
            }
            // Place labels on the Form
            Controls->AddRange(labels);
        }

        System::Void rtBox_KeyDown(System::Object^ sender, 
                                   System::Windows::Forms::KeyEventArgs^ e)
        {
            try
            {
                if (rtBox->SelectionLength > 0) 
                {
                    // Change selected text style
                    FontStyle fs;
                    switch (e->KeyCode) 
                    {
                        case Keys::F1: 
                            fs = FontStyle::Bold;                    
                            break; 
                        case Keys::F2: 
                            fs = FontStyle::Italic;                   
                            break; 
                        case Keys::F3: 
                            fs = FontStyle::Underline;
                            break; 
                        case Keys::F4: 
                            fs = FontStyle::Regular;
                            break; 
                    // Change selected text color
                        case Keys::F5: 
                            rtBox->SelectionColor = Color::Red; 
                            break; 
                        case Keys::F6: 
                            rtBox->SelectionColor = Color::Blue; 
                            break; 
                        case Keys::F7: 
                            rtBox->SelectionColor = Color::Green; 
                            break; 
                        case Keys::F8: 
                            rtBox->SelectionColor = Color::Black; 
                            break; 
                    }

                    // Do the actual change of the selected text style
                    if (e->KeyCode >= Keys::F1 && e->KeyCode <= Keys::F4)
                    {
                        rtBox->SelectionFont = gcnew Drawing::Font( 
                            rtBox->SelectionFont->FontFamily, 
                            rtBox->SelectionFont->Size, 
                            fs 
                        );
                    }
                }
                // Load hard coded Chapter01.rtf file
                else if (e->KeyCode == Keys::F9)
                {
                    rtBox->LoadFile("Chapter01.rtf");
                }
                // Save hard coded Chapter01.rtf file
                else if (e->KeyCode == Keys::F10)
                {
                    rtBox->SaveFile("Chapter01.rtf", 
                                    RichTextBoxStreamType::RichText);
                }
            }
            // Capture any blowups
            catch (Exception ^e)
            {
                MessageBox::Show(String::Format("Error: {0}", e->Message));
            }
        }
  };

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