Click to See Complete Forum and Search --> : what events are used when using the mainmenu component?


bumholo
April 8th, 2004, 04:48 PM
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:

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.

Craig Gemmill
April 8th, 2004, 05:56 PM
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/sandbar/sandbar-freeware.zip
http://www.divil.co.uk/net/controls/dotnetwidgets/dotnetwidgets-1.1.zip

bumholo
April 9th, 2004, 04:28 AM
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.

coolbiz
April 9th, 2004, 06:22 AM
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

DSJ
April 9th, 2004, 08:05 AM
MainMenu is not inheritable.

DSJ
April 9th, 2004, 08:52 AM
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.

bumholo
April 9th, 2004, 12:55 PM
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.

DSJ
April 9th, 2004, 02:08 PM
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

bumholo
April 9th, 2004, 03:01 PM
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?

:confused:

Craig Gemmill
April 10th, 2004, 09:29 AM
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)

bumholo
April 10th, 2004, 11:28 AM
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.