How To Get A Reference To A Command's Category?

Docking/MDI for Windows Forms Forum

Posted 14 years ago by JohnH
Avatar
re: UIStudio 2.0 beta release

Say I have a textBox in a toolWindow. When the 'Enter' event fires on the textBox, I want to set the visible property to false on the category named 'Tools' on the mainMenu.

How do I get a reference to the 'Tools' category on the mainMenu?

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

Correct me if I'm wrong but I think you mean that you have a BarPopupButtonLink on the main menu with the text "Tools" and you want to hide it, right? For review, there are two ways to design popup menu items:

1) Make a BarPopupButtonCommand named "MenuBar.Tools" and drag/drop it on the main menu. This way you can just use this code:
barManager.MenuBar.CommandLinks["MenuBar.Tools"].Visible = false;
That is the recommended way of designing main menus, because it then allows you to properly have customizable root menus that your end users can drag/drop (assuming you populated the "MenuBar.Tools" command's DefaultCommandLinks.

OR

2) Make a BarPopupButtonCommand named "New Menu.New Menu" and drag/drop it on the main menu. Then set its text to "Tools". The problem with this method is that you can't simply reference the Tools menu by its command full name since "New Menu.New Menu" is probably shared by other menu items. So here you'd have to figure out through iteration which command link in the MenuBar.CommandLinks is the one to hide. Once you find the right one, hide it.

Hope that helps.


Actipro Software Support

Posted 14 years ago by JohnH
Avatar
"I think you mean ... BarPopupButtonLink"
- Yep. I'm still learning the object model; there's a lot to it.

Anyway, I still can't get the 'Tools' menu/CommandLink to be not visible. The compiler returns "'ActiproSoftware.UIStudio.Bar.BarCommand' does not contain a definition for 'Visible'". I used the "1)" example you provided.

I used the Customize dialog to setup the 'MainMenu' menubar by clicking the 'Create Standard Command Links on Selected Bar Control' link in the 'Toolbars...' tab as well as 'Create Standard Commands' on the 'Commands' tab. Does this equate to your comment, "Make a BarPopupButtonCommand named "MenuBar.Tools""; what am I missing?

Thanks much!
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

I think you're confusing commands and command links. Commands have no UI and are what is designed in the designer's Customize dialog. When you drag a command and drop it on a toolbar, it creates a command link that points back to that command.

So while the designer's Customize dialog is displayed, left click on your Tools command link (on the menubar). Then on the Customize dialog, go to the Selected Command Link tab. You should see a Visible property there.

Our "create standard xxx" links currently just use the "New Menu.New Menu" approach for making the menus although we might enhance that in the future for something like what I described in #1 since that's a better practice.


Actipro Software Support

Posted 14 years ago by JohnH
Avatar
Thanks much(!) for reply, but I'm still not seeing how to set the visible property for a commandLink to false at runtime.

Here's where I'm at:
In Designer:
1. Under the Selected Command Link tab, for a Edit.Cut commandLink, I see the visible property, which is set to true.
2. I drop a textBox in a toolWindow.

For my runtime requirement (in code file):
1. In the Enter event of the textBox, I have this (and only this),
barManager.MenuBar.CommandLinks["Edit.Cut"].Visible = false;.
2. Since there's no Visible property on CommandsLinks, the compiler throws an error, "ActiProSoftware.UIStudio.Bar.BarCommand does not contain a defintion for Visible".

I can dis/enable easy enough with "barManager.Commands["Edit.Cut"].Enabled = false" but how do I set visible property for a commandLink at runtime?
Posted 14 years ago by JohnH
Avatar
Ok, the light-just-came-on; I get it now.

In my earlier post I mentioned the requirement to make the commandLink, "&Edit", not visible, in the Enter event of a textBox. (Ok so, maybe hiding the Edit menu isn't a good idea, but this is just a test.)

Solution:
The solution is simple. I merely needed to create a BarCommandLink object set to the commandLink on the MenuBar like so;

ActiproSoftware.UIStudio.Bar.BarCommandLink bcl = barManager.MenuBar.CommandLinks[1];
bcl.Visible = false;


Wow. I'm sold. This UIStudio is pretty slick!
The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.