我有一个自定义类的按钮,当我触发PerformClick
任何自定义按钮时,什么都没有发生。这是代码:
我的自定义类的声明
public class NonFocusButton : Button
{
public NonFocusButton()
{
SetStyle(ControlStyles.Selectable, false);
}
}
List<NonFocusButton> buttons = new List<NonFocusButton>();
这是p
功能:
void p()
{
for (int i = 1; i <= 5; i++)
{
NonFocusButton aux = new NonFocusButton();
aux.Font = new System.Drawing.Font("Britannic Bold", 15.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
aux.Size = new System.Drawing.Size(192, 43);
aux.UseVisualStyleBackColor = true;
aux.UseWaitCursor = false;
aux.Visible = false;
buttons.Add(aux);
this.Controls.Add(aux);
}
// button start
buttons[0].Location = new System.Drawing.Point(410, 168);
buttons[0].Text = "START GAME";
buttons[0].Click += new System.EventHandler(this.button0_Click);
}
private void button0_Click(object sender, EventArgs e)
{
this.Close();
}
buttons[0].PerformClick(); // will not work