467,882 Members | 1,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,882 developers. It's quick & easy.

making a custom context menu

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

Nov 20 '05 #1
  • viewed: 8139
Share:
6 Replies
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

"Bob" <no*****@nospam.net> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2
Hello,

"Bob" <no*****@nospam.net> schrieb:
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

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
Bob
Thank you. A rather nice example.

Bob

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
Hello,

"Bob" <no*****@nospam.net> schrieb:
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

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet


Nov 20 '05 #4
Bob
www.dotnetmagic.com sells its controls so I'm not likely to get the source :(

I like those menus though. It's very close to what I want to do.

Bob

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:O8**************@TK2MSFTNGP12.phx.gbl...
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

"Bob" <no*****@nospam.net> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
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



Nov 20 '05 #5
Hello,

"Bob" <no*****@nospam.net> schrieb:
www.dotnetmagic.com sells its controls so I'm not likely
to get the source :(

I like those menus though. It's very close to what I want to do.


You will find the free version (+ source code) here:

http://sourceforge.net/projects/dotnetmagic/

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
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

"Bob" <no*****@nospam.net> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
www.dotnetmagic.com sells its controls so I'm not likely to get the source :(
I like those menus though. It's very close to what I want to do.

Bob

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:O8**************@TK2MSFTNGP12.phx.gbl...
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

"Bob" <no*****@nospam.net> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Roman Muntyanu | last post: by
8 posts views Thread by Dennis C. Drumm | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.