c# 多个控件(combobox)共用同一点击事件
2021-03-08 16:28
标签:www mes gui tco href res vat ESS gate mark: https://zhidao.baidu.com/question/1754127113219248788.html https://www.cnblogs.com/gxy19fly/archive/2007/07/10/812854.html https://www.cnblogs.com/guiqiang/p/4632667.html 方法一: portComboBox1.Click += new EventHandler(refreshPort3); private void refreshPort3(object sender, EventArgs e) try } 方法二: foreach (Control c in Panel1.Controls) ((ComboBox)sender).Items.Clear(); ((ComboBox)sender).Items.Clear(); } } c# 多个控件(combobox)共用同一点击事件 标签:www mes gui tco href res vat ESS gate 原文地址:https://www.cnblogs.com/chinayixia/p/12785748.html
portComboBox2.Click += new EventHandler(refreshPort3);
portComboBox3.Click += new EventHandler(refreshPort3);
{
{
List
string[] ports = USB.GetPorts(); //SerialPort.GetPortNames();//
if (sender == portComboBox1)
{
portComboBox1.Items.Clear();
for (int i = 0; i {
portComboBox1.Items.Add(ports[i]);
}
if (ports.Length > 0)
{
portComboBox1.SelectedIndex = ports.Length - 1;
}
}
if (sender == portComboBox2)
{
portComboBox2.Items.Clear();
for (int i = 0; i {
portComboBox2.Items.Add(ports[i]);
}
if (ports.Length > 0)
{
portComboBox2.SelectedIndex = ports.Length - 1;
}
}
if (sender == portComboBox3)
{
portComboBox3.Items.Clear();
for (int i = 0; i {
portComboBox3.Items.Add(ports[i]);
}
if (ports.Length > 0)
{
portComboBox3.SelectedIndex = ports.Length - 1;
}
}
}
catch (Exception ex)
{
MetroMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK);
}
{
if (c is ComboBox)
{
c.Click += delegate (object sender, EventArgs e)
{
try
{
List
string[] ports = USB.GetPorts(); //SerialPort.GetPortNames();//
for (int i = 0; i {
((ComboBox)sender).Items.Add(ports[i]);
}
if (ports.Length > 0)
{
((ComboBox)sender).SelectedIndex = ports.Length - 1;
}
}
catch (Exception ex)
{
MetroMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK);
};
}
文章标题:c# 多个控件(combobox)共用同一点击事件
文章链接:http://soscw.com/index.php/essay/61891.html