日期:2014-05-18 浏览次数:21074 次
private void Form1_KeyDown(object sender,KeyEventArgs e) { if(e.Alt&&e.KeyCode==Keys.Delete) {删除用户选定的项} }
private void listBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Alt && e.KeyCode == Keys.Delete) { listBox1.Items.Remove(listBox1.SelectedItem); listBox1.SelectedIndex = 0; } }
------解决方案--------------------
if(e.Alt&&e.KeyCode==Keys.Delete)
ListBox1.Items.Remove(ListBox1.SelectedItem);
或
while (listBox1.SelectedItems.Count != 0)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
}