Tutorial 3 : Windows Forms and Useful ListBox Properties Using Visual C++.NET 2010, 2008
This program will show how to use listboxes, and some of their more useful properties. Click here for the source code to the ListBox Demo Program in Visual C++.NET for the 2010 version or click here to download the 2008 version. First create a form which looks as follows, including the one listBox shown:
Code the buttons as followings:
Note: If you lose the design window (which often
happens when you open the “sln” file using explorer) try the
following:
Navigate to File > New > Project > Window Form Application
To make a design window appear which shows the forms go to view > designer
This program will show how to use listboxes, and some of their more useful properties. Click here for the source code to the ListBox Demo Program in Visual C++.NET for the 2010 version or click here to download the 2008 version. First create a form which looks as follows, including the one listBox shown:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
listBox1->Items ->Add(textBox1->Text );
textBox1->Text="";
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
int numListBoxItems;
numListBoxItems=listBox1->Items ->Count;
label2->Text=numListBoxItems.ToString() ;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
int position;
String ^myString;
myString=textBox2->Text;
position=listBox1->Items->IndexOf(myString);
label4->Text=position.ToString();
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
{
String ^newWord;
int position;
newWord=textBox3->Text;
position=Int32::Parse(textBox4->Text);
listBox1->Items->Insert(position, newWord);
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e)
{
listBox1->Sorted=true;
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e)
{
String ^myString;
myString=textBox5->Text;
listBox1->Items->Remove(myString);
}
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e)
{
int position;
String ^myString;
myString=textBox6->Text;
position=Int32::Parse(myString);
listBox1->Items->RemoveAt(position);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
|
Navigate to File > New > Project > Window Form Application
To make a design window appear which shows the forms go to view > designer
1 comments:
Can you explain the purpose and functionality of the buttons coded in the tutorial, specifically focusing on button1_Click and how it adds items to the listbox?
Greting Telkom University
Post a Comment