I have created a custom control which extends GroupBox. This control supports collapsing and expanding and I use the GroupBoxRenderer and ButtonRenderer to make it look like a typical GroupBox that has a Button in the corner. I have handled all the appropriate mouse events which effectively make the "button" behave and look like a regular Button. Now I have hit a problem where the GroupBox does not receive focus using TabStop. Is there anyway that I can get my Collapsable GroupBox to receive focus from a TabStop?
I was hoping that I could use the trick from How to set focus to a control after validation in .NET to set the focus in the Enter event but I haven't come up with a good way of determining when it should actually get the focus. I could probably devise a way of finding the siblings with the next highest and lowest TabIndex (or ChildIndex if the same TabIndex) and then determine if they lost focus but this seems a bit hacky and a high chance of breaking if I don't get it exactly right.
Note: I did initially create user control but this was not what I wanted for various reasons including:
- It is not a control that contains a button and a groupbox (it just so happens to sort of look that way), it is a groupbox
- Flexibility
- Coupling between backend code and UI
- Dynamic layout
- Shared across many projects which require Toolbox support and customising the UI and layout of the entire control
Here is what it looks like when expanded:
And now when it has been collapsed (and has focus):