"電腦沒裝VB6.0,用的VS2010請參考Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("耗油生菜") ListBox1.Items.Add("清蒸魚") ListBox1.Items.Add("醬爆雞翅") ListBox2.Items.Add("大米") ListBox2.Items.Add("饅頭") ListBox2.Items.Add("麵條") End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged TextBox1.Text = "" For Each item In ListBox1.SelectedItems TextBox1.Text += item + "," Next TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1) End Sub Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged TextBox2.Text = ListBox2.SelectedItem End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = "你選擇的菜是:" + TextBox1.Text + ",你選擇的主食是:" + TextBox2.Text End SubEnd Class
"電腦沒裝VB6.0,用的VS2010請參考Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("耗油生菜") ListBox1.Items.Add("清蒸魚") ListBox1.Items.Add("醬爆雞翅") ListBox2.Items.Add("大米") ListBox2.Items.Add("饅頭") ListBox2.Items.Add("麵條") End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged TextBox1.Text = "" For Each item In ListBox1.SelectedItems TextBox1.Text += item + "," Next TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1) End Sub Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged TextBox2.Text = ListBox2.SelectedItem End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = "你選擇的菜是:" + TextBox1.Text + ",你選擇的主食是:" + TextBox2.Text End SubEnd Class