• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2809
  • Last Modified:

ToolStripMenuItem.visible always false

Hello

I have a problem with the "visible" attribute of ToolStripMenuItem.

I have a form with a ToolStrip containing two ToolStripMenuItem buttons. I've been setting the visible attribute of these two buttons to false depending on the users permissions.
I'm now trying to re-size the ToolStrip according to how many of the buttons are visible. The problem occurs when I come to test the value of ToolStripMenuItem.visible.
It always seems to be false until the form has completeley finished drawing. So I can't count how many of the buttons are going to be visible.

How can I accurately test the visible attribute of a ToolStripMenuItem ?
0
Rusty_Adams
Asked:
Rusty_Adams
  • 2
  • 2
1 Solution
 
sumixCommented:
It is true, visible property of ToolStripMenuItems is false until the form is loaded. You should handle Load event of the form and set there this property.

Note: ToolStripMenuItem can be part of a MenuStrip or a ContextMenuStrip control. If you use a ToolStrip containing ToolStripButtons you have ToolStrip.AutoSize property you can use, but again, visible property for ToolStripButtons should be set in Load event.
0
 
Rusty_AdamsAuthor Commented:
Thankyou

Using the load event of the form solved my problem.
Although I don't see how the ToolStrip.AutoSize is of any use. I still had to re-size the tool strip myself.
At what point is the AutoSize property supposed to take effect?

0
 
sumixCommented:
By default, ToolStrip has Dock property set to Top or Bottom. The resize can only take place if Dock is set to None, otherwise the size is linked with the size of the container.
0
 
Rusty_AdamsAuthor Commented:
That's strange. My toolstrip is not docked at all, and AutoSize is set to true. Yet it doesn't appear to perform any sort of auto re-size.
0
 
smeggheadCommented:
It seems that the 'Available' property reflects whether the item has been set to visible or not.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now