ToolStripButton have different behavior on showing Modal Less Dialog

485 views Asked by At

I have a main window and a toolstrip on it with different command buttons. In these commands, I've a 'Print' button too (See Below). When I click on 'Print' button , I need to show sub-form as Modal Less Dialog. Because, I've few option on sub-form. If user select them then he/she can interact with Main Form too.

enter image description here

Meanwhile, on show() method I disable all controls on Main Form (see below) as it will be done if I use ShowDialog() method to show sub-form. When I click the Print Button, it's color changed which shows it is focused/selected.

enter image description here

On click sub-form is show like below pic.

enter image description here

Logically, it should return to previous mode when I close sub-form. But, even sub-form is showing... that 'Print' button on Main-Form is still focused/selected. When I close the sub-form, that 'Print' Button still focused/selected like below.

enter image description here

What Event/ Property needs to be changed to make this 'Print' Button to show like as it is in initial state.

I've tried Invalidate(), change BackColor but didn't meet the requirement yet. Any Guidelines ?

2

There are 2 answers

0
Itz.Irshad On BEST ANSWER

Well, Selected Property in ToolStripButton is read only. Anyone, needs to clear the selection of toolstrip buttons can use below method which is invoked via reflections.

MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
            method.Invoke(yourToolStripName, null);

This comes from : How to Deselect ToolStripItems

Happy Programming.

1
roken On

Set the CheckOnClick property of your button to false if you don't want it to appear "selected" at all, otherwise toggle the CheckState property on the button when the subform is closed.