日期:2014-05-18 浏览次数:21046 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace trytry { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton6_CheckedChanged(object sender, EventArgs e) { if (radioButton6.Checked == true) listBox1.MultiColumn = true; } private void radioButton5_CheckedChanged(object sender, EventArgs e) { if(radioButton5.Checked == true) listBox1.MultiColumn=false; } private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (radioButton3.Checked == true) listBox1.SelectionMode = SelectionMode.MultiSimple; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { label1.Text=""; //如果是单选,则使用SelectedItem返回所选项 if(listBox1.SelectedIndices.Count==1) label1.Text=listBox1.SelectedItem.ToString(); else{ //如果是多选,则使用SelectedItems返回所有的所选项 for(int i=0;i<listBox1.SelectedIndices.Count;i++) label1.Text+=listBox1.SelectedItems[i].ToString() + " ";} } private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked == true) listBox1.SelectionMode = SelectionMode.One; } private void radioButton4_CheckedChanged(object sender, EventArgs e) { if (radioButton4.Checked == true) listBox1.SelectionMode = SelectionMode.MultiExtended; } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true) listBox1.SelectionMode = SelectionMode.None; } } }