我有一個自定義的按鈕類,當我觸發我的任何自定義按鈕PerformClick
時,什麼都不會發生。這是代碼: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
顯示更多完整的代碼。這裏沒有足夠的上下文來找出問題出在哪裏...... –