Graphic menu
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Graphic menu

  1. #1
    Join Date
    Feb 2009
    Posts
    3

    Graphic menu

    Hi!

    I'm tired of the text based menus in C# visual studio 2005.

    Most software today have menus with icons.

    I realize I have to make the icons in fx. photoshop, but how do i use them as menus in a C# application? Is there a way to import them and use them as menu items?

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Graphic menu

    Create your own menu item class and override OnPaint. You'll have to set the UserDraw and AllPaintingInWMPaint flags as well via the SetStyle method. BTW, I am assuming WinForms here because you didn't specify and due to the fact that this is trivial in WPF.

  3. #3
    Join Date
    Jan 2010
    Posts
    1,102

    Re: Graphic menu

    @OP: Operating on the assumption that you are not talking WPF here, it's better not to mess with OnPaint() unless you're sure you know what you're doing - luckily, with Windows Forms it's also a breeze - assuming you're not looking for something too fancy; with .NET 2.0 came the ToolStripMenuItem class, which "replaces and adds functionality to the MenuItem control of previous versions". The new class works in conjunction with the MenuStrip class (also new to .NET 2.0), and provides an Image property that can be set and basically represents an icon. Some appearance tweaks are also possible. ToolStripMenuItem also provides the Checked property, which enables you to put a check mark in-there.

    You can load some bitmaps or gifs as resources, or load an image from file. You can set the icon in the code, in the properties window, or you can right-click on the menu item and choose "Set Image...".

    Just make sure it's a MenuStrip that you drag on your form, and not a MainMenu.

    (If I'm not mistaken, VS2005 comes with .NET 2.0, right?)

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Graphic menu

    In VS 2005, .NEt Framework 2.0, contains a MensuStrip control which has the capability to add icons to menu items. Play around with its properties

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Graphic menu

    Wow, I can't believe I didn't know that you can add images so easily...

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: Graphic menu

    Don't worry, it also took me a while to figure it out - some time ago. It happens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center