making a custom context menu

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I'd like to be able to do three things with the context menu

1. change the width
2. change the borderstyle to none
3. change the back color

I don't think it's possible, so what's the best way to make my own menu-like
control?

TIA,
Bob
 
Bob,
I'm not sure about #2, but #1 & #3 you can easily do with Owner Draw menus.
If you can do #2 I suspect it will need to be down with Owner Draw menus as
well...

For owner draw menus I normally derive a new class from MenuItem, set the
OwnerDraw property to yes in the constructor, then override the
OnMeasureItem & OnDrawItem methods.

The trick is the menu designer does not understand these derived classes,
what I do is design the menu as normal, then very carefully modify the
"Windows Form Designer generated code" to change
System.Windows.Forms.MenuItem to MyProject.MyMenuItem.

You can do it without deriving a class by handling the MeasureItem &
DrawItem events, however its not as clean (OOP) as deriving a class.

For more complete samples of OwnerDraw MenuItems you can refer to the source
at
www.dotnetmagic.com or Charles Petzold's book "Programming Microsoft Windows
with Microsoft Visual Basic.NET" has a sample.

Hope this helps
Jay
 
Hello,

Bob said:
I'd like to be able to do three things with the context menu

1. change the width
2. change the borderstyle to none
3. change the back color

I don't think it's possible, so what's the best way to make my
own menu-like control?

You will find a simple sample for an ownerdrawn menu here:

Adding icons to menus in VB.NET
http://www.codeproject.com/vb/net/iconsmenu.asp
 
Bob,
I forgot that dot net magic recently started charging for source.

As the download I have had the source in it.

Thanks for reminding me.

Jay
 
Back
Top