PerformClick上的自定义按钮将无法正常工作 [英] PerformClick on custom button will not work
本文介绍了PerformClick上的自定义按钮将无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义类按钮,当我触发 PerformClick
对我的任何自定义按钮,没有任何反应。这是code:
我的自定义类的宣言
公共类NonFocusButton:按钮
{
公共NonFocusButton()
{
的SetStyle(ControlStyles.Selectable,FALSE);
}
}清单< NonFocusButton>按钮=新的List< NonFocusButton>();
这是 P
功能:
无效P()
{
的for(int i = 1; I< = 5;我++)
{
NonFocusButton AUX =新NonFocusButton();
aux.Font =新System.Drawing.Font(大不列颠大胆,15.75F,
System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,
((字节)(0)));
aux.Size =新System.Drawing.Size(192,43);
aux.UseVisualStyleBackColor =真;
aux.UseWaitCursor = FALSE;
aux.Visible = FALSE;
buttons.Add(辅助);
this.Controls.Add(辅助);
} //键式启动 键[0] = .Location新System.Drawing.Point(410,168);
键[0]。文本=开始游戏;
键[0]。点击+ =新System.EventHandler(this.button0_Click);
}私人无效button0_Click(对象发件人,EventArgs的发送)
{
this.Close();
}键[0] .PerformClick(); // 不管用
解决方案
如何按钮声明,填补?这是我拥有它,和它的作品。
//声明
清单<按钮和GT; butons =新的List<按钮和GT;();//调用
buttons.Add(新按钮());
ρ();
键[0] .PerformClick();
编辑:
按钮已获得焦点,可以单击它之前。结果
为什么不这样做:
button0_Click(键[0],EventArgs.Empty);
或只是叫关闭()
随时随地可以调用 PerformClick()
。
I have a custom class of a button and when I trigger PerformClick
for any of my custom buttons, nothing happens. This is the code:
Declaration of my custom class
public class NonFocusButton : Button
{
public NonFocusButton()
{
SetStyle(ControlStyles.Selectable, false);
}
}
List<NonFocusButton> buttons = new List<NonFocusButton>();
This is the p
function:
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
解决方案
How are buttons declared and filled? This is how I have it, and it works.
// declaration
List<Button> butons = new List<Button>();
// calling
buttons.Add(new Button());
p();
buttons[0].PerformClick();
Edit:
The button has to get focus before it can be clicked.
Why not do something like:
button0_Click(buttons[0], EventArgs.Empty);
or just call Close()
from wherever you are calling PerformClick()
.
这篇关于PerformClick上的自定义按钮将无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文