我试图这样做(我的领域),但是当我点击它时我无法看到= false任何按钮。 顺便说一句,this.visible = false将以可见的形式出现 - .-
private void Form1_Load(object sender, EventArgs e)
{
this.Size = new Size(541, 537);
for (int j = 24; j < ClientSize.Height; j += 25)
{
for (int i = 0; i < ClientSize.Width; i += 25)
{
Button btn = new Button();
btn.Width = 25;
btn.Height = 25;
btn.Location = new Point(i, j);
btn.Click += btn_Click;
Controls.Add(btn);
}
}
}
void btn_Click(object sender, EventArgs e)
{
//When i clicked anyone of them that comes be invisible,
}
thx for help
答案 0 :(得分:2)
触发事件的控件存储在sender
中 - 将其强制转换为Button
。
void btn_Click(object sender, EventArgs e)
{
var button = (Button)sender;
button.Hide();
}
或者,如果你在活动中所做的一切,你可以在一行中定义它:
btn.Click += delegate { btn.Hide(); };