这是新控件添加代码部分:
for (int i = 0; i < 1; i++)
{
var newLabel = new Label();
newLabel.Location = new Point(x, y);
newLabel.Size = new System.Drawing.Size(25, 25);
newLabel.Name = "lbl" + realpocsed.ToString();
if (value2== "Value2")
{
newLabel.MouseMove += new MouseEventHandler(this.MyControl_MouseMove);
newLabel.MouseDown += new MouseEventHandler(this.MyControl_MouseDown);
}
if (value== "Value1")
{
newLabel.MouseDown += new MouseEventHandler(this.MyControl_MouseHover);
}
panel1.Controls.Add(newLabel);
事件MouseHover
如下所示:
private void MyControl_MouseHover(object sender, MouseEventArgs e)
{
ToolTip ToolTip1 = new ToolTip();
ToolTip1.ShowAlways = true;
ToolTip1.Show("t", X); // X should be name of the newly created label
}
请问有没有办法用 name"lbl" + realpocsed.ToString()
而不是分配新创建的X
?
感谢您的时间。