Group box with title as Check box

ぐ巨炮叔叔 提交于 2019-12-22 05:24:16

问题


I am using Visual Studio 6.0 (VC++ with MFC) in Windows XP platform. I am trying to create a group box with the title of the group box as a check box. My intention is this: If the check box is enabled, the controls inside the group box should be enabled; or else disabled.

Is this possible to accomplish? If yes, please give me some directions.

Thanks.


回答1:


There are a few things you can try, depending on how true you want to stay to your idea and how much work you are prepared to put into the effort:

Simple method

Use a normal group box, and then inside this make the first item be the checkbox. This is simple to accomplish, but you lose the goal of having the checkbox as the title.

Funky drawing method 1

Use a normal group box, then in the space over where you know the title is to go, place your checkbox. You will have to perform some tricky calculation to get it to fit in nicely and draw well without flicker.

Funky drawing method 2

Use some form of superclass or subclass/subclass on the group box. You can override the WM_PAINT handler to draw in only the frame for the group box. Place a normal checkbox in the place where you know the title is to go. This should work better because you will have more control over the drawing, but it is likely to be tricky to get right. In my experience, subclassing is lower risk to implement than superclassing.




回答2:


Are you using the Dialog editor? If so, put down the group box. Next, on top of it, put a check box over the line of the group box. Edit the resource to set the Z order, or do it in code. You want the checkbox to be on top of the group box. Add a handler for the checkbox and enable / disable controls depending on the check box state.




回答3:


I wrote one called CGroupCheck a few years back and it's available from CodeProject: http://www.codeproject.com/KB/buttons/groupcheck123.aspx



来源:https://stackoverflow.com/questions/1047951/group-box-with-title-as-check-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!