By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

making a custom context menu

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.