[英]How can I create a Drop Down Menu in C#
Could somebody help me with my problem on my drop down menu? 有人可以在下拉菜单中为我解决问题吗?
I have 4 buttons inside the panel. 我在面板内部有4个按钮。 The size of each button is 132
, 29
. 每个按钮的大小为132
, 29
。 My problem is when I hover the mouse on the button nothing happens. 我的问题是,当我将鼠标悬停在按钮上时,什么也没发生。
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);
}
Because you move mouse on buttons not the panel object. 因为您将鼠标移到按钮上而不是面板对象上。 Write a hover event handler for one of the buttons and assign it to all four buttons "MouseHover" event handlers and in your code you can find out mouse moved over which button : 为其中一个按钮编写一个悬停事件处理程序,并将其分配给所有四个按钮“ 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.