Kiran
Kiran

Reputation: 8528

C# Drop Down menu with labels in Winforms

I would like to have a drop down menu in Winforms in C# with Text Label in between the menu items. It will be very similar to seperators. So basically I am looking at an option of grouping the menu items.

Any idea how we can achieve it ? Attached is the drop-down menu I wish to have. enter image description here

Upvotes: 1

Views: 3632

Answers (3)

helgeheldre
helgeheldre

Reputation: 1101

I'm sure there are many complex ways to do this but i've found one that might satisfy your needs in 3 Steps:

1.You make your own ToolStripItem:

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)]
public sealed class CustomToolStripMenuItem : ToolStripMenuItem
{

    public CustomToolStripMenuItem()
    {
        DisplayStyle = ToolStripItemDisplayStyle.Text;
        BackColor = Color.LightSteelBlue;
        ForeColor = Color.MidnightBlue;
        Font = new Font(Font, FontStyle.Bold);
       // Or other options to your liking
     }
}

2.You make your own Renderer:

public class CustomeRenderer : ToolStripProfessionalRenderer
{

    protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
    {
        if(e.Item is CustomToolStripMenuItem)
        {
            e.Graphics.FillRectangle(Brushes.LightSteelBlue, e.Item.ContentRectangle);
        }
        else
        {
            base.OnRenderMenuItemBackground(e);
        }
    }
}

3.Use your items: For your contextmenu you need to set up the renderer:

 RenderMode = ToolStripRenderMode.Professional;
 Renderer = new CustomeRenderer();

In your context menu you can now use your CustomToolStripMenuItem

Upvotes: 0

CRoshanLG
CRoshanLG

Reputation: 498

Hope you are using VS2010

In the Menu Designer, right-click the location where you want a separator bar, and choose Convert To -> Separator.

enter image description here


MSDN Article on menu enhancements


You might want take a look at this also (Its about form separators, but version is VS2003!) -- Windows Forms Separator Control

Upvotes: 2

Rohit Vyas
Rohit Vyas

Reputation: 1969

May be below link can help you:

A Seperator Combo List Vox

Upvotes: 0

Related Questions