有人可以在下拉菜单中为我解决问题吗?
我在面板内部有4个按钮。每个按钮的大小分别为132
,29
。我的问题是,当我将鼠标悬停在按钮上时,什么也没发生。
int t1 = 29;
private void pnlFeature_MouseHover(object sender, EventArgs e)
{
timer1.Start();
}
private void pnlFeature_MouseLeave(object sender, EventArgs e)
{
timer1.Stop();
t1 = 29;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (t1 > 116)
{ timer1.Stop(); }
else
{
this.pnlFeature.Size = new Size(this.pnlFeature.Size.Width, t1);
t1 += 4;
}
}
private void frmMain_MouseHover(object sender, EventArgs e)
{
this.pnlFeature.Size = new Size(this.pnlFeature.Size.Width, t1);
}
答案 0 :(得分:3)
因为将鼠标移到按钮上而不是面板对象上。 为其中一个按钮编写一个悬停事件处理程序,并将其分配给所有四个按钮“ MouseHover”事件处理程序,在代码中,您可以找到鼠标移至哪个按钮上:
private void button1_MouseHover(object sender, EventArgs e)
{
if (!(sender is Button))
return;
Button tmp = (Button) sender;
switch (tmp.Name)
{
case "Button1":
break;
case "Button2":
break;
case "Button3":
break;
}
}