Using for Add Items in ListBox




#pragma once

namespace My52 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ BtnAddItems;
protected:
private: System::Windows::Forms::ListBox^ lst;
private:
///
/// Required designer variable.
///

System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->BtnAddItems = (gcnew System::Windows::Forms::Button());
this->lst = (gcnew System::Windows::Forms::ListBox());
this->SuspendLayout();
//
// BtnAddItems
//
this->BtnAddItems->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast
(222)));
this->BtnAddItems->Location = System::Drawing::Point(12, 149);
this->BtnAddItems->Name = L"BtnAddItems";
this->BtnAddItems->Size = System::Drawing::Size(377, 42);
this->BtnAddItems->TabIndex = 0;
this->BtnAddItems->Text = L"Add Items";
this->BtnAddItems->UseVisualStyleBackColor = true;
this->BtnAddItems->Click += gcnew System::EventHandler(this, &Form1::BtnAddItems_Click);
//
// lst
//
this->lst->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast
(222)));
this->lst->FormattingEnabled = true;
this->lst->ItemHeight = 25;
this->lst->Location = System::Drawing::Point(14, 19);
this->lst->Name = L"lst";
this->lst->Size = System::Drawing::Size(375, 104);
this->lst->TabIndex = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(401, 203);
this->Controls->Add(this->lst);
this->Controls->Add(this->BtnAddItems);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
//Using for Add Items in ListBox
private: System::Void BtnAddItems_Click(System::Object^ sender, System::EventArgs^ e) {
int i;
for(i=0;i<=50;i++) { lst->Items->Add("Index : "+i);
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->BackColor=Color::Red;
this->Text="Using for Add Items in ListBox";
this->MaximizeBox=false;
lst->BackColor=Color::Yellow;
lst->ForeColor=Color::Red;
BtnAddItems->BackColor=Color::Black;
BtnAddItems->ForeColor=Color::White;
}
};
}