Toggling buttons on a toolstrip

Started by
2 comments, last by myvraccount 7 years, 11 months ago

This is ridiculous! All I'm trying to do is select and deselect a toolstrip button when I click it, the same way the "Left Align" button I'm looking at right now is selected in this text editor.

So I try to call select on the button, but nothing happens. I found out the hard way that it's because the canSelect property is false, but it's read only, because it's calculated from other things (like whether it's visible etc.).

So I looked up what would make it true, so if I change that manually, then when I call select, it should work right?

Well the main thing is that there's an enumeration type called ControlStyle, which has a flag in it called Selectable. This enumeration is supposed to be hidden somewhere in Control, and it can only be changed by calling SetStyle(ControlStyle, bool) - so I guess I set one bool at a time to true or false.

I couldn't find it, but I managed to find it in a different project on a different computer in a different version of .NET (yay for potential incompatibilities! I think the other one it using VS2010 or something, maybe 2012).

Anyway, I only found it in Form, but I still can't find it in ToolStrip or ToolStripButton. Don't they inherit Control? And if not, how can I actually make them selectable, and WHY aren't they by DEFAULT?!?!

Also, I'd like to be able to select and deselect them independently so I can select multiple simultaneously so I can have image buttons that act like checkboxes.

I've spent a few hours on something that should have taken a few SECONDS and now I'm really aggravated! Please tell me how to do this.

Thanks.

Advertisement

It's the stupidest thing! It turned out that I needed the CHECKED property, not the SELECTED property!!! why would anyone call it CHECKED if there's not actually a check mark?!?!?! This is maddening!!! What does selected even do then? How is highlighting it when I click it not the same as selecting it?!

Under the hood they are secretly check boxes. The status of the checkbox indicates if the image should be popped in or popped out, or grayed out.

Selected generally refers to the cursor.

Well that makes sense, but I wish they'd implement it in a more intuitive way. I almost never would have figured that out, and I was on the wrong track for the better part of a day!

This topic is closed to new replies.

Advertisement