![Image 1](/KB/miscctrl/simplest_checkable_group/screenshot.gif)
Introduction
Lots of time we want to disable a set of controls in our dialog. Group box is a good control to categorize a few controls together, but unfortunately it cannot enable/disable its controls. I extended CButton
class and made it very simple to accomplish this and it is encapsulated into one class.
So you can change the title of a group box into a check box or radio button (then you need more group boxes of course).
I must confess I borrowed some idea of other talented programmers.
How to use it
- Draw a group box in resource editor as usual. In resource editor, change the style property of group box to icon or bitmap, this prevents Overlapped text when tab is pressed!
![Styles Page](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
You can also enable tab key navigation by enabling Tab Stop in group box resource like following
![Gerenal Page](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
- Add a member variable for this added group box, but choose
CCheckableGroupBox
as control type.
- In
OnInitDialog()
, call m_yourVariable.SetTitleStyle(BS_AUTOCHECKBOX);
to change normal title to a check box, or use BS_AUTORADIOBUTTON
for radio box.
- you want a group of group box toggle by radio box title, just create more Checkable group box as you already did, and call
SetGroupID
to give them a group!
- In updated version of this control, I support
DDX_Check
, which means now you can use UpdateData()
to update and save the state of check box in an standard MFC fashion.
Because the check/radio box is created when SetTitleStyle()
is called, no variable update is applicable before that point. If you want to update the status from a member variable, please call UpdateData(FALSE)
after that. I know it's not perfect but it's not that bad anyway.
History
- Updated (21/11/03) - Supports windows
WM_ENABLE
message. Now you can call EnableWindow()
to disable the whole group!
- Updated (24/11/03) - Suppot
DDX_Check
for variable exchange. Please refer to demo project for details. Tab support by enable tab stop style in resource.
- Updated (02/12/03) - Send
BN_CLICKED
Message to parent dialog while title box is clicked. This is crucial if you use this control along with my Data Driven UI Behaviour Pattern.
- Updated (03/12/03) - Support embedded group boxes (Groupbox inside another), no level or number limitations!
I have over 13 Years IT industry experience as Principle/Senior Programmer. I am experienced in .NET/J2EE system design and detailed implementation. I master UML modelling and OO design methodology with a strong C#/C++/Java coding background. I have been in working/managing a distributed project using Agile/Waterfall approach. My business knowledge includes Telecommunication, Financial Investment/Trading, and Banking.