winform中 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { comboBox1.Items.Clear(); videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); for (int i = 0; i < videoDevices.Count; i++) comboBox1.Items.Add(videoDevices[i].Name); comboBox1.Text = comboBox1.Items[0].ToString(); } 取消按钮,让combobox实现功能
时间: 2024-02-14 17:11:41 浏览: 97
如果你想要在取消按钮上实现comboBox更新的功能,你可以在取消按钮的Click事件处理程序中调用UpdateComboBox函数,UpdateComboBox函数中的代码会更新comboBox的下拉列表数据。
下面是一个简单的实现:
```
private void UpdateComboBox()
{
comboBox1.Items.Clear();
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
for (int i = 0; i < videoDevices.Count; i++)
comboBox1.Items.Add(videoDevices[i].Name);
comboBox1.Text = comboBox1.Items[0].ToString();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Do something when the selected index of comboBox1 changes
}
private void button1_Click(object sender, EventArgs e)
{
// Do something when the button1 is clicked
}
private void button2_Click(object sender, EventArgs e)
{
UpdateComboBox();
}
```
在这个示例中,我们添加了一个名为button2的按钮,并将其Click事件处理程序设置为UpdateComboBox函数。当用户点击button2时,UpdateComboBox函数会更新comboBox1的下拉列表数据。
阅读全文