0
我已经创建了一个按钮,下面的代码。在按钮的左下角创建了一个标签。代码工作正常,但当用户单击标签时按钮没有响应,请帮助。C#标签按钮
自定义按钮:
public class CustomButton : System.Windows.Forms.Button
{
private System.Windows.Forms.Label lb = new System.Windows.Forms.Label();
public CustomButton(){
this.Width = 120;
this.Height = 65;
this.Font = new System.Drawing.Font(this.Font.FontFamily, 24);
lb = new System.Windows.Forms.Label();
lb.Font = new System.Drawing.Font(lb.Font.FontFamily, 9);
lb.Location = new System.Drawing.Point(4,35);
lb.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
lb.BackColor = System.Drawing.Color.Transparent;
lb.Width = 70;
this.Controls.Add(lb);
}
public System.Windows.Forms.Label getLb()
{
return lb;
}
public System.Windows.Forms.Button get_btn()
{
return this;
}
}
的WinForm:
public CustomButton[,] bt = new CustomButton[13,32];
public FormClient()
{
bt[0, 0] = new CustomButton();
bt[0, 0].Click += new EventHandler(button_Click);
}
public void button_Click(object sender, EventArgs e)
{
//my code//
}
你不能将按钮事件处理程序分配给标签吗? – EpicKip
只需添加一个eventHandler标签上点击您的CustomButton,这将引发按钮点击事件 – VDN
'lb.Width = 70; lb.Click + = this.Click; this.Controls.Add(lb);' – TaW