How to get a reference to a BarButtonLink at runtime?

Bars for Windows Forms Forum

Posted 14 years ago by JohnH
Avatar
RE: UIStudio version 2/Bar Control/.NET Framework 2.0

The form Designer generates this code:
ActiproSoftware.UIStudio.Bar.BarButtonLink fileNewBarButtonLink = new ActiproSoftware.UIStudio.Bar.BarButtonLink(fileNewBarButtonCommand);

So at runtime, I want to set some properties on this BarButtonLink. How do I get a reference to this BarButtonLink at runtime?

I've tried every thing I can think of. For example, this seems like it should work, but bbc returns null.
BarButtonCommand bbc = (BarButtonCommand)barManager.MenuBar.CommandLinks["File.New"];

"Newing-up" a BarButtonLink doesn't work either.

For a test, if I scope fileNewBarButtonLink to be public, then I'm all set; I have the reference that I want, but, of course, the designer will overwrite the changes.

Thanks!

Comments (1)

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

Command links can be customized by the end user and added or deleted by them as well. Therefore we don't expose them as public member variables since they may be removed by the end user and the reference would be invalid. Also new links added by the end user wouldn't be available via a member variable.

But for your indexer code, it looks like you found a bug. Using a command full name on the CommandLinks indexer is supposed to return the first BarCommandLink in the collection that is based on a command with that full name. However we mistakenly are returning the BarCommand that the BarCommandLink is based on. That is now fixed for the next maintenance release.

Also in your sample code, "File.New" links are probably on a toolbar, not the menubar. So you need to do something like barManager.DockableToolBars["Standard"] instead. But since you found that bug with the string-based indexer, you'll have to use the IndexOf method to get the link's index and then call the indexer that accepts an index parameter to get the link. Once the maintenance release comes out then you can switch back the code to more like what you have.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.