热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

vc中CheckBox有时候感觉失效,点击的时候没有选上,打不上勾

vc中CheckBox有时候感觉失效,点击的时候没有选上在开发中遇到过一次这种问题,点击CheckBox时,前面总是打不上勾但是有事件发送下去。后来比较

vc 中 CheckBox 有时候感觉失效,点击的时候没有选上

 

在开发中遇到过一次这种问题,点击CheckBox 时,前面总是打不上勾

但是有事件发送下去。

 

后来比较了一下这个Checkbox 和其他的差别,发现Style属性也重Auto 没有选上。

 

选上后,一切正常。

====

多方查找该问题, 最好在一篇英文中找到,

http://www.devarticles.com/c/a/Cplusplus/Using-MFC-in-C-Controls-DDX-and-DDV/3/

 

 


(Page 4 of 9 )

As with the EDITTEXT control, we create both the check box control within our resource file. Updating our example resource file, we would add a check box, like this:

AUTOCHECKBOX "Able to vote?", IDCB_CANVOTE, 20, 35, 50, 15, WS_VISIBLE | WS_CHILD | WS_TABSTOP

This would add a check box to our dialog box. Its caption would be set to “Able to vote?”. MFC provides two types of check boxes: The CHECKBOX, and the AUTOCHECKBOX control. In our example above, I have used the AUTOCHECKBOX control, simply because if we chose the CHECKBOX control, we would have to handle the checking and un-checking of the box manually, which is just a pain.

The syntax of the CHECKBOX control is shown below:

[AUTO]CHECKBOX [Caption], [Control Id], [X Pos], [Y Pos], [Width], [Height], [Style Options]

The caption of the check box is the text that will be displayed next to the check box. The control id is a numerical id, which is #defined within another header file. In our example, we have used IDCB_CANVOTE. I have prefixed the check box controls id with IDCB, which is representational for “Check Box Identification”. You can, however name your controls id’s whatever you like.

It’s really simple to get and set the value of a check box control. As you can probably guess, a check box is either on or off, 1 or 0. We retrieve the value of our check box control like this:

int checkState;

CButton* pCheck = (CButton*)GetDlgItem(IDCB_CANVOTE);

checkState = pCheck->GetCheck();


As with the EDITTEXT control, we retrieve a reference to the control via its id. The check box control is a member of the CButton class, so we cast it as such. The GetCheck method of the CButton class returns the current value of our check box: 0 for not checked, or 1 for checked.

To set the value of our check box control, we can use the SetCheck method, like this:

CButton* pCheck = (CButton*)GetDlgItem(IDCB_CANVOTE);

pCheck->SetCheck(1);


That’s pretty much all you need to create and use a check box control because they are so simple. Let’s now look at the radio button control.

Using MFC in C++ Part 4: Controls, DDX and DDV - The check box control

 

 

原来Auto如果没有选上的话,需要在它的事件里面手动调用

SetCheck()

来给复选框打上勾。

 

如果选上Auto的话,则系统自己打上勾了。

 

 


推荐阅读
author-avatar
东张西望
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有