简体   繁体   English

如何在C#中创建下拉菜单

[英]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 . 每个按钮的大小为13229 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.

相关问题 如何在 WinForms 和 C# 中创建下拉菜单 - How to create a drop down menu in WinForms and C# 如果下拉菜单不是选择元素,如何将Webdriver与C#一起使用,如何通过文本选择下拉项? - Using webdriver with c# how can I select a drop down item by text if the drop down menu is not a select element? 如何根据asp.net C#下拉菜单中的用户输入在图表上添加一条直线 - How can I add a straight line on my chart on the basis of user input from drop down menu in asp.net c# 如何使用Selenium C#拍摄下拉菜单的屏幕截图? - How to take screenshot of drop-down menu with Selenium C#? 使用c#的webdriver-如何在选项下拉菜单中进行迭代? - webdriver with c# - How do I iterate around an option drop down menu? .NET下拉菜单C# - .Net drop down menu c# c#中的下拉菜单(位置和使用) - Drop Down Menu in c# (position and use) 我如何在DataGridView中的C#中创建上下文菜单 - How can i create a context menu in c# in a datagridview 如何使用C#在ASP MVC中的下拉列表中创建唯一的日期列表? - How do I create a unique list of dates in a drop down in ASP MVC with C#? 如何在c#中为动态下拉列表创建事件处理程序 - how to create event handler for dynamic drop down list in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM