โปรแกรม 12.4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace program12_4
{
public partial class dipplay : Form
{
public dipplay()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = list1.SelectedIndex;
display.Text = list1.Items[index].ToString();
}
private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
int index = list2.SelectedIndex;
display.Text = list2.Items[index].ToString();
}
}
}
โปรแกรมที่ 12.5
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace program12_5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void add_Click(object sender, EventArgs e)
{
string str = text.Text;
listBox.Items.Add(str);
}
}
}
โปรแกรมที 12.6
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace program12_5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void add_Click(object sender, EventArgs e)
{
string str = text.Text;
listBox.Items.Add(str);
}
private void delete_Click(object sender, EventArgs e)
{
int index = listBox.SelectedIndex; //อ่านค่าอินเด็กซ์ของไอเท็มที่เลือก
listBox.Items.RemoveAt(index); //ลบข้อมูลในตำแหน่งที่เลือก
}
private void clear_Click(object sender, EventArgs e)
{
listBox.Items.Clear(); //เคลียร์ค่าไอเท็มในลิสต์บ็อกซ์
}
private void number_Click(object sender, EventArgs e)
{
MessageBox.Show("The number of items in the list is " +
listBox.Items.Count.ToString());
}
}
}