Toggle Buttons in toolbar

42 views
Skip to first unread message

vorp

unread,
May 28, 2015, 9:56:19 PM5/28/15
to authoring-to...@googlegroups.com
Hello all.
I'm trying to use ICommandService to add a menu and toolbar with buttons that can act as toggles.
Normal buttons work great with the RegisterCommand function and some custom image resources.
However, toggling buttons have escaped me.
For example a pause button: once pressed it looks different (darker) and then you press it again to unpause and it goes back to the original look.
I figured I could grab the CommandInfo from the the RegisterCommand call and then tweak the image to represent the change of state.
However, if I grab the CommandInfo object and change its members, the button doesn't change to follow.
Is there another approach? The CommandInfo class suggests that there should be a dynamic update to buttons/menu items.
Or do I need to use a completely custom control?

Thanks for any suggestions.

-Len

vorp

unread,
Jun 1, 2015, 2:04:58 PM6/1/15
to authoring-to...@googlegroups.com, l...@lenwhite.com
Ok...Solved this. Looks like the CommandInfos are, in fact, working as expected, though certain fields like Checked do nothing.
I was able to swap images using this technique and got what I needed.

-Len

Ron2

unread,
Jun 1, 2015, 2:14:49 PM6/1/15
to authoring-to...@googlegroups.com, l...@lenwhite.com
Oh, cool, Len. I was *just* starting to look into your question. Yeah, some properties can be set at any time and the changes will be recognized, but other properties are for initialization only. I'll go through and double-check the code comments about this.

--Ron

vorp

unread,
Jun 2, 2015, 6:12:31 PM6/2/15
to authoring-to...@googlegroups.com, rona...@gmail.com, l...@lenwhite.com
Thanks Ron.
On a related note, do you know if there's any way to invoke the "down" or "pressed" state of a toolbar button?
I'm doing it with custom images now but it might be better to use the system pressed state, if possible.
Thanks.

-Len

Ron AtSony

unread,
Jun 2, 2015, 6:49:54 PM6/2/15
to vorp, authoring-to...@googlegroups.com
Hi Len,

Maybe you can use the .NET ToolStripButton instead of an image. You can add the button to the tool strip and then set its Checked property to true, which should put it in the pressed state.

Here's an example from LevelEditor, where we add a ToolStripComboBox to the tool strip for the Edit menu. The key line is "MenuInfo.Edit.GetToolStrip().Items.Add()".

            m_pickFilterComboBox = new ToolStripComboBox();
            m_pickFilterComboBox.BeginUpdate();

...

            m_pickFilterComboBox.EndUpdate();            
            MenuInfo.Edit.GetToolStrip().Items.Add(m_pickFilterComboBox);
            m_pickFilterComboBox.SelectedIndexChanged += PickpickFilterComboBox_SelectedIndexChanged;

            m_settingsService.RegisterSettings(this,new BoundPropertyDescriptor(this, () => ActivePickFilter, "ActiveFilter",null, null));


--Ron


--
You received this message because you are subscribed to the Google Groups "Authoring Tools Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to authoring-tools-fr...@googlegroups.com.
Visit this group at http://groups.google.com/group/authoring-tools-framework.
For more options, visit https://groups.google.com/d/optout.

vorp

unread,
Jun 3, 2015, 3:54:16 PM6/3/15
to authoring-to...@googlegroups.com, rona...@gmail.com, l...@lenwhite.com
Excellent. That generally works.
However, I'm getting strange ordering of my toolstrip buttons. It doesn't seem to matter when I add my own controls in code, they get juggled around in order with the controls added via commandService.RegisterCommand.
For example, I add a label followed by a textbox but then one of my RegisterCommand controls gets inserted in between. Weird.
Is there any control over this that you know of?
Thanks.

-Len

To unsubscribe from this group and stop receiving emails from it, send an email to authoring-tools-framework+unsub...@googlegroups.com.

Ron AtSony

unread,
Jun 4, 2015, 11:57:12 AM6/4/15
to vorp, authoring-to...@googlegroups.com
I think you're seeing a timing issue between when the WindowLayoutService is restoring the layout of the toolstrip and when you've added the controls to the toolstrip. If my theory is correct, you would need to register your command and add the controls earlier during start-up, because the layout can only be applied to existing Controls. (I recall one exception to that rule -- document-related Controls can have the layout applied later, after the document is loaded.)

--Ron

To unsubscribe from this group and stop receiving emails from it, send an email to authoring-tools-fr...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Authoring Tools Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to authoring-tools-fr...@googlegroups.com.

vorp

unread,
Jul 28, 2015, 9:48:06 PM7/28/15
to Authoring Tools Framework, rona...@gmail.com, rona...@gmail.com
Hi Ron.
I'm running into the above issue again and I'm not sure how to do what you're suggesting.
I've got some buttons I'm adding manually that don't order among themselves correctly based on when I call toolstrip.Items.Add()
Do all my buttons need to have a corresponding RegisterCommand() call? Since I'm adding them separately and playing some games with up and down states, I didn't think it necessary, but maybe it is?
Currently they are just being added to the ToolStrip "manually" after the normal set of RegisterCommand() calls.
Thanks.

-Len

vorp

unread,
Jul 28, 2015, 9:53:43 PM7/28/15
to Authoring Tools Framework, l...@lenwhite.com, rona...@gmail.com, l...@lenwhite.com
Ok...I think the problem is related to the user being able to re-order controls via an Unlocked UI state.
When I delete those entries from the appSettings.xml the Add order works.

Follow up: What is the way to 
1. Remove the ability to reorder individual controls?
2. Remove the "Customize" drop downs?

Thanks.
-Len

vorp

unread,
Jul 28, 2015, 10:04:59 PM7/28/15
to Authoring Tools Framework, l...@lenwhite.com, rona...@gmail.com, l...@lenwhite.com
A specific example: I need a Trackbar in the Toolstrip. It needs some kind of label. I'd like to use an icon. I can't have the user reordering the label away from the Trackbar.

-Len

Ron2

unread,
Jul 30, 2015, 5:26:30 PM7/30/15
to Authoring Tools Framework, l...@lenwhite.com, l...@lenwhite.com
Hi Len,

I'm confused about how the user can move individual controls around within a toolstrip; DockPanelSuite (our underlying 3rd party library) doesn't support that. These controls can be toggled on/off through that Customize drop-down menu. The user can reposition entire toolstrips which must be what you're talking about. The only way to prevent toolstrips from being repositioned by the user is to lock the UI with the Window -> Lock UI Layout command. It should be possible to do that programmatically and then hide the Lock UI Layout command button, if you want.

Unfortunately, we don't support removal of the "Customize" drop-down menu. It wouldn't be hard to add a new property to CommandService (Sce.Atf.Applications namespace), to control whether the private method AddCustomizationDropDown() is called. (Submit a pull request?)

As to how to combine a label with a trackbar, this is not currently possible through CommandInfo and CommandService, because CommandService expects to work with buttons. I think the crux of your problem is that you need to combine the label and track bar together into one object that gets added to the tool strip. I played around with ToolStripControlHost and added it to the Edit menu's tool strip...

var label = new Label();
label
.Text = "Volume";
var trackBar = new TrackBar();
trackBar
.Minimum = 0;
trackBar
.Maximum = 11;
           
var containerControl = new ContainerControl(); //or use a derived class? Form? UserControl?
containerControl
.Controls.Add(label);
containerControl
.Controls.Add(trackBar);

var toolStripHost = new ToolStripControlHost(containerControl);
MenuInfo.Edit.GetToolStrip().Items.Add(toolStripHost);





I don't know why the slider grip/knob doesn't appear or how to control the resulting size. Probably you can use Visual Studio's Designer to create a UserControl that contains both the Label and TrackBar, and then add that UserControl to a ToolStripControlHost which you can then finally add to the ToolStrip. 

If you can get this working, I'd appreciate seeing a code snippet of how you did it. That might help others in the future.

Sorry I can't be of more help right now.

--Ron
Reply all
Reply to author
Forward
0 new messages