前几天下载了一个C#电梯小程序,里面21个楼层按钮,只用了一小段代码处理,通过每个按钮的Tag来区分,部分代码如下:namespace lift
{
public partial class Form1 : Form
{
int destion = 0;//目的楼层
int number = 0;//所到楼层
public Form1()
{
InitializeComponent();
this.skinEngine1.SkinFile = "OneGreen.ssk";
}
private void lift_click(object sender, EventArgs e)
{
if (destion == 0)
{
destion = Convert.ToInt32(((Button)sender).Tag);
((Button)sender).BackColor = Color.Red;
}
else
{
MessageBox.Show("你只能选择一个楼层","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}请问,
1,这里的lift_click中的lift是指什么呢?
2,如果我想要用这样的方法实现大量的类似的菜单选项的选择响应,对应上面的lift_click,菜单的应该怎么写呢?
请高人指点一二~谢谢
{
public partial class Form1 : Form
{
int destion = 0;//目的楼层
int number = 0;//所到楼层
public Form1()
{
InitializeComponent();
this.skinEngine1.SkinFile = "OneGreen.ssk";
}
private void lift_click(object sender, EventArgs e)
{
if (destion == 0)
{
destion = Convert.ToInt32(((Button)sender).Tag);
((Button)sender).BackColor = Color.Red;
}
else
{
MessageBox.Show("你只能选择一个楼层","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}请问,
1,这里的lift_click中的lift是指什么呢?
2,如果我想要用这样的方法实现大量的类似的菜单选项的选择响应,对应上面的lift_click,菜单的应该怎么写呢?
请高人指点一二~谢谢
看看我的代码
foreach (Control myc in form1.Controls)
{
if (myc is TextBox)
{
TextBox tb = (TextBox)myc;
tb.Text = string.Empty;
}
if (myc is CheckBox)
{
CheckBox cb = (CheckBox)myc;
cb.Checked = false;
}
}
先写一个lift_click方法,
再把按钮的Click事件委托给lift_click方法,
是不是这样啊?
我试试看先。
5楼的搜索所有控件的代码也很有参考价值,THANKS!