| An Example (Cont.) |
|
|
using System;
using System.Windows.Forms;
namespace WindowsFormsApp2 {
public partial class Array : Form {
public Array( ) { InitializeComponent( ); }
private void addName( ) {
string[ ] studentName = new string[5];
for ( int i = 0; i < 5; i++ ) {
studentName[i] = Microsoft.VisualBasic.Interaction.InputBox(
"Enter the student name:" );
nameList.Items.Add( studentName[i] );
}
}
private void Start_Click( object sender, EventArgs e ) {
nameList.Items.Clear( );
addName( );
}
private void Exit_Click( object sender, EventArgs e ) {
Application.Exit( );
}
}
}
|
ListBox control displays a list from which the user can select one or more items.
ListBox.Items property gets the items of the ListBox.
ListBox.Items.Add method adds an item to the list of items for a ListBox.
ListBox.Items.Clear method removes all items from the list.
Microsoft.VisualBasic.Interaction.InputBox work for C#, add the Microsoft.VisualBasic by using the Reference Manager:
WindowsFormsApp2 in the Visual Studio,Add, andReference....