473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ToolStripMenuItem Possible bug in VS2005

I begin a new form. I add a MenuStrip. I then right click it and select
"Insert Standard Items". This results in a loaded MenuStrip that contains
File>>New among others.

I then add a button and give it the following code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Static b As Boolean
b = Not b
NewToolStripMenuItem.Visible = b
Debug.Print(NewToolStripMenuItem.Visible.ToString)
End Sub

This code toggles the visibility of the "New" menu item. This code works
correctly regarding the item visibility. Unfortunately, my Debug.Print
statement always prints "False" whether or not it is visible. Needless to
say, this causes me problems because I have sections of code that determine
what to do based upon a menu item being visible.

Can someone confirm this behaviour and suggest a different way for
determining if a menu item is visible. My only apparent alternative would be
to create a form level boolean variable that would shadow whether the menu
item is visible but this seems like a dumb way to resolve the issue.

Needless to say, this was not a problem with the old MainMenu control.
Oct 11 '06 #1
2 2620
I've verified your results.

On top-level menu items which are always visible, reading .Visible
works properly.

On sub-menu items which are not currently displayed, reading .Visible
always returns False, regardless of whether or not they *would* be
visible once that item is displayed. Which kinda makes sense if you
think about it, but it's not what you want.

So yes, you will have to shadow the property in some way. You could
toggle .Enabled to the same value and read it instead.

Oct 11 '06 #2
genojoe wrote:
I begin a new form. I add a MenuStrip. I then right click it and select
"Insert Standard Items". This results in a loaded MenuStrip that contains
File>>New among others.

I then add a button and give it the following code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Static b As Boolean
b = Not b
NewToolStripMenuItem.Visible = b
Debug.Print(NewToolStripMenuItem.Visible.ToString)
End Sub

This code toggles the visibility of the "New" menu item. This code works
correctly regarding the item visibility. Unfortunately, my Debug.Print
statement always prints "False" whether or not it is visible. Needless to
say, this causes me problems because I have sections of code that determine
what to do based upon a menu item being visible.

Can someone confirm this behaviour and suggest a different way for
determining if a menu item is visible. My only apparent alternative would be
to create a form level boolean variable that would shadow whether the menu
item is visible but this seems like a dumb way to resolve the issue.

Needless to say, this was not a problem with the old MainMenu control.
I've encountered the same problem and found the Available property.

This seems to work in all cases.

Dec 9 '06 #3

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

Similar topics

2
by: Maileen | last post by:
Hi, I've create an application which includes : - a toolstrip - a toolstripmenu - several toolstripmenuitem(s) so, now i have a menu like that : -File
2
by: genojoe | last post by:
I have a VB 2003 project that I have updated to 2005. I notice that MenuItem is being phased out and replaced by ToolStripMenuItem. I want to investigate the new capabilities of this new control...
0
by: genojoe | last post by:
I have a menu structure that formats that left aligns string1 and right aligns string2. To do this, I use the OwnerDraw, Popup, DrawItem and MeasureItem properties or events of the MenuItem class....
1
by: =?Utf-8?B?RjVGNUY1?= | last post by:
I have created a control by inheriting ToolStripMenuItem that has an image property called LargeImage. ------ public class EventSubMenuItem : ToolStripMenuItem { private Image _largeImage =...
1
by: Justin Cherniak | last post by:
I have a ToolStrip item which fires a function when clicked. The function will run to completion without any problems (if I set a breakpoint at the closing brace, no exception has been fired), but...
3
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I need to show a custom control in the DropDown of a Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in Word except that the control is specific to my application). I...
2
by: in10se | last post by:
I am trying to mimic the functionality of a web browser's "Favorites" (or "Bookmarks") menu. I would like to be able to right-click on a ToolStripMenuItem and have a context menu appear so that I can...
0
by: Dean Slindee | last post by:
I need to be able to separate toolstripmenuitems from toolstripseparators, both of which are children of a toolstripdropdropbutton. The last statement does not pass validation. Is there any way...
3
by: Martijn Mulder | last post by:
My application has a standard MenuStrip on top of the window and a ContextMenuStrip that pops up when the user clicks the right mouse button. I have defined a ToolStripMenuItem that I want to...
0
by: kyungdongkim | last post by:
Hi, I have a dynamically generated MenuStrip following this example: http://www.codeproject.com/useritems/Dynamic_MenuStrip.asp Basically the menu strip allows users to save and load reports. ...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.