CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2003
    Location
    UK
    Posts
    69

    Question what events are used when using the mainmenu component?

    Evening all,

    If I wanted to create my own enhanced MainMenu control from scratch by inheriting from the MainMenu control provided by Microsoft, what events would I need to implement?

    i.e. what I want to do is add a few new properties to the mainmenu and menuitem properties to add new functionality to the control, for example add icons and colour to the menuitems.

    I'm guessing that my control would have two classes:
    Code:
    Public Class EnhancedMainMenu : Inherits System.Windows.Forms.MainMenu
    
       ' Functions & Subs go here
    
    End Class
    
    
    Public Class EnhancedMenuItem : Inherits System.Windows.Forms.MenuItem
    
       ' Functions & Subs go here
    
    End Class
    but how do I get the two classes to talk to each other so that when I add the control to my form I can build menus as I would if I were using the standard MainMenu control supplied by Microsoft?

    Thanks in advance,

    B.

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    Did you check out those two examples I gave you earlier? It would answer a lot of these questions...

    You might want to take a look at the class design for these two assemblies to get an idea on how to approach this:

    http://www.divil.co.uk/net/controls/sandbar/
    http://www.divil.co.uk/net/controls/dotnetwidgets/
    Here is the direct downloads:
    http://www.divil.co.uk/net/controls/...r-freeware.zip
    http://www.divil.co.uk/net/controls/...idgets-1.1.zip
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Sep 2003
    Location
    UK
    Posts
    69

    Exclamation

    Yeah, thanks Craig I did have a look at the two links but the downloads didn't have the source files with them and I didn't understand the couple of articles on the site.

    I'm quite new to vb.net but I'm finding it very difficult to find anyone who knows how to do what I'm trying to do. The only solutions I've found so far are by creating an extender control which applies the visual changes to an existing menu on an application. I don't think this is a very efficient way to do it, it would be much more efficient and tidy if there was just one Menu control which had a smart visual style.

    I've had a look at a few different versions of VB and I can't believe that Microsoft find it acceptable to ship basically the same menu control through all versions. The standard menu control is poor and MS clearly have a better menu control which they use in VS.NET and Office XP/2003, so why not realease it as a VS.NET control? Sun have a great menu control in the Java SDK which implements icons and color properties to the control.

    Anyway that was a bit of a ramble, but hey! that's my frustration trying to write this control. I figure if I can understand which subs are fired from the MainMenu control to implement the MenuItems object when a menu control is used in an app then I will be able to write the control myself.

    Any more thoughts you have would be very much appreciated,

    B.
    Last edited by bumholo; April 9th, 2004 at 04:34 AM.

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Well, when you inherit from the base class, your derived class will work without any modification (unless base class requires you to override its method(s) - MUSTINHERIT keyword).

    The same thing w/ MAINMENU and MENUITEM classes. It is up to you which methods/properties that you want to override/overload/shadow so that your menu can be enchanced.

    Look at MSDN overview and class members on those classes. If a method/property has OVERRIDABLE keyword, it means you can override it w/ your own. If it has MUST OVERRIDE, then you'll have to override it (otherwise it won't compile). You can also always OVERLOADS any public/protected methods/properties exposed by the base class.

    What exactly you need to override/overload/shadow? I don't have specific answers for that but why not experiment w/ some right? If you don't mind post your findings so that we can take a look at it too

    -Cool Bizs

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    MainMenu is not inheritable.

  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    Originally posted by bumholo

    The only solutions I've found so far are by creating an extender control which applies the visual changes to an existing menu on an application. I don't think this is a very efficient way to do it, it would be much more efficient and tidy if there was just one Menu control which had a smart visual style.

    B.
    I don't really see anything inefficient about the way that control is working. All it's doing is hooking up a new eventhandler for the measureitem and drawitem methods of the menuitem class.

  7. #7
    Join Date
    Sep 2003
    Location
    UK
    Posts
    69
    Well DSJ I think that with a modern development environment there should be some modern controls to use but microsoft seem to disagree and continue to package out of date styled controls with it's current visual studio .net IDE.

    If you take a look at the Java 1.4 SDK supplied by SUN, they supply modern controls for developers to use, something I think Microsoft should give some serious thought to doing, otherwise, I think eventually it will become laughable to even think of developing modern applications with a creeky old set of tools which make application look 5 or 6 years too old.

    Coolbiz I created my own class called EnhancedMenu and inherited from the MainMenu class but could find no methods which would let me get a handle to the MenuItem class so that I could substitue the microsoft supplied MenuItem class with my own. All my own written MenuItem class does is use the MeasureItem and DrawItem methods to add icons and colour to the Menu in my apps.

    Any ideas?

    B.

  8. #8
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    So program in java then.

    If you want to manage the image list, etc. from the IDE then the MenuExteder class is the way to go. If you just want to do what you stated above, then add a call to InitMyMenu() after InitalizeComponent() in your FormLoad() and add this code:

    Private Sub InitMyMenu()
    Dim mnuitm As MenuItem
    For Each mnuitm In Me.MainMenu1.MenuItems
    mnuitm.OwnerDraw = True
    AddHandler mnuitm.DrawItem, AddressOf YourDrawFunction
    AddHandler mnuitm.MeasureItem, AddressOf YourMeasureFunction
    Next
    End Sub

  9. #9
    Join Date
    Sep 2003
    Location
    UK
    Posts
    69
    DSJ, I have created the app in Java but as much as I like the freedom that Java gives you and the excellent components it is just too darn slow!!!

    So back to go ole' VB.NET which brings me back to the problem of only having old visualy styled controls, as supplied by microsoft, to play with.

    So, the plan was to make new controls which I could reuse in other projects. So far I've created new textbox, combo box, listbox and treeview controls which have advanced features such as regular expressions, colour attributes, case attributes, xml support, etc... all within each control requiring no extra programming from the user other than to set some properties on the control once added to a form.

    Now I want to be a bit more adventurous and create my own menu control which supports coloured backgrounds, icons, user selected highlighting and newer visual stylings ala' OfficeXP/2003 or VS.NET.

    I know how to do all the coding to put icons on the menu items and change colours, etc... but what I don't know is how to create my own menu control which I can drop onto a form, change some properties to have icons displayed and colours change without having to hook some sort of user written class into the microsoft supplied menu control to achieve that result.

    Any help you can provide to do that would be very much appreciated.

    B.


    P.S.
    Am I the only one that thinks the controls supplied by microsoft in the VS.NET IDE are very poor visually when you compare them to the visual style of apps being produced at the moment?

    Last edited by bumholo; April 9th, 2004 at 03:03 PM.

  10. #10
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    Originally posted by bumholo
    ...Am I the only one that thinks the controls supplied by microsoft in the VS.NET IDE are very poor visually when you compare them to the visual style of apps being produced at the moment?...
    It appears they agree...

    VS2005 (.net2.0) will have a lot of new features in its GUI related controls.

    A couple of these improvements will be:

    -MainMenu (most notably, will have image support)
    -WinBar (much like CoolBar in 6.0, or MSOffice)
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  11. #11
    Join Date
    Sep 2003
    Location
    UK
    Posts
    69
    Yipee!!!!

    That is good news. Think I will head over to microsoft.com and try and findout when they plan to release VS.NET 2005.


    Thanks,

    B.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured