473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

OwnerDraw property for Menus

This code is derived from:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JUL.1033/cpref/html/frlrfSystemWindowsFormsMenuItemClassOwnerDrawTopic .htm

The sample works as presented but does not contain a click event. Here is
my abridged version of the code. In this code, if I use MenuItem2.OwnerDraw
= False, it behaves as expected: no ownerdraw and when clicked, I see the
message.

If MenuItem2.OwnerDraw = True, I see the colored text but when I click,
nothing happens. How can I have colored text that responds to the click
event?
--------------------------------------------------------------------------------------
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
MenuItem2 = New MenuItem("Custom Menu Item")
MenuItem2.OwnerDraw = True
AddHandler MenuItem2.DrawItem, New DrawItemEventHandler(AddressOf
DrawCustomMenuItem)
AddHandler MenuItem2.Click, AddressOf MenuItem2Click

MainMenu1 = New MainMenu(New MenuItem() {MenuItem2})
Me.Menu = Me.MainMenu1
components = New System.ComponentModel.Container
Me.Text = "Form2"
End Sub

#End Region
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Private Sub DrawCustomMenuItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs)
Dim customItem As MenuItem = CType(sender, MenuItem)
Dim aBrush As System.Drawing.Brush =
System.Drawing.Brushes.DarkMagenta
e.Graphics.DrawString(customItem.Text, e.Font, aBrush, e.Bounds.X,
e.Bounds.Y)
End Sub

Private Sub MenuItem2Click(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("This is a test")
End Sub
End Class


Nov 21 '05 #1
0 1030

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jm | last post by:
Is it possible to change the appearance of text (color of fonts, etc.) in the systray with OwnerDraw like in "regular" context menus? I am having trouble doing it and was wondering if it was...
5
by: Rob Mayo | last post by:
How can I force a MeasureItem message for an owner-dramn menu item? Here is the dilemma. I wrote a lovely little Component for owner-drawing all the menus on a form and making them look like...
2
by: anand | last post by:
Hi All, Are ownerdraw buttons supported in C# ? I have an active X control which I would like to use in CSharp. Buttons have a style BS_OWNERDRAW, and to do custom drawing you have to...
0
by: Apollo440 | last post by:
If MenuItem.OwnerDraw Property is true,.NET framework does not recognize the overlapped accelerator keys. Is there a workaround? eg) +------+ |&Test | <- |&Tea | <- MenuItems has...
2
by: Stuart Norris | last post by:
Dear Group, I am new to c# and windows form designer - coming from a Motif background. I am attempting to develop an application for a touch screen and I need to have a menu system with a...
2
by: jm | last post by:
There are properties for OwnerDraw on ContextMenu items. I know it can be done with regular menus. I cannot find anyone doing it with the systray icon contextmenu (notifyicon.) Is it possible to...
0
by: Peter Proost | last post by:
Hi group, I was wondering if anyone has ever done this before, I've got a working ownerdrawn menu the only thing I can't get to work is to ownerdraw the items the get automaticaly created in a...
2
by: Peter Proost | last post by:
Hi group, I've got this ownerdraw menu module which I got from a site and modified to my personal needs, but the only problem I'm having is with the lines in a menu, when you type - as text, it...
1
by: tmda | last post by:
I'm using OwnerDraw for some customization in my ListView - adding color to item backgrounds. I'm using the ListView specifically for it's OwnerDraw capability. I originally was using the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.