当前位置:网站首页>MFC控件学习:按钮
MFC控件学习:按钮
2022-07-15 09:42:00 【霸道小明】

目录
1.给按钮添加事件
2.单选框使用方式
3.复选框使用方式
1.给按钮添加事件
可以通过右击控件选择事件添加

也可以在属性栏→控制事件添加

再者就是通过双击按钮直接进入事件响应函数(单击响应事件)

2.单选框使用方式
上面这种Button是最常见的按钮,当然也有其他类型的按钮例如Check Box和Radio Box

Check Box和Radio Box的区别在于Check Box是复选框而Radio Box是单选框
可以用Group Box将其框起来,让他们看起来是一组的

将单选框里的第一个Radio 的Group设为True,就可以把这四个单选框绑定成一个变量,实现单选的功能。


给这一组单选框绑定一个变量,用来获取用户点击的Radio


在Dlg.h文件中可以看到绑定的变量,如果变量值为0,则表示选择的是第一个按钮,依次递加

修改Button控件的代码,使其能弹出单选框的值
void CdialogDlg::OnBnClickedButton1()
{
CString str;
//整型转字符串
str.Format(_T("%d"), m_RadioChose);
MessageBox(str);
}
我们发现不管选则哪个Radio Box,弹出的值都是0,这是因为将控件转为绑定的变量时,需要更新他的值。
在Button点击函数中添加UpdateDate()函数
void CdialogDlg::OnBnClickedButton1()
{
//同步控件与变量,True:将控件值同步到变量上,False:不同步。默认为True
UpdateData();
CString str;
//整型转字符串
str.Format(_T("%d"), m_RadioChose);
MessageBox(str);
}UpdateDate()函数可以将在界面上做出的操作结果反应到绑定的变量上

如果想实时将控件的选择和变量值一致时,就需要使用UpdateDate()函数
3.复选框使用方式
复选框需要为每一个选框绑定一个变量

修改Button 响应事件,查看用户选择
void CdialogDlg::OnBnClickedButton1()
{
//同步控件与变量,True:将控件值同步到变量上,False:不同步。默认为True
UpdateData();
CString str;
//整型转字符串
str.Format(_T("选框1=%d\n选框2=%d\n选框3=%d\n选框4=%d\n"), m_check1, m_check2, m_check3, m_check4);
MessageBox(str);
}

边栏推荐
- JMeter regular expression gets login token
- Letter combination of leecode17 phone number
- Meituan side: @transactional principle and common pits?
- Process testing
- Is decentralized science the new trend of Web 3.0?
- CF1265E Beautiful Mirrors (概率dp)
- The solution that background attribute editing cannot load after dedecms dream changes the include directory rename
- 【数学建模暑期培训】Matlab的数据处理
- 小程序 拉起企业微信进群二维码
- Four thinking abilities that front-line technicians should pay attention to
猜你喜欢

Topological sorting principle

The file of penetration test contains Vulnerabilities & utilization posture
![[advanced C language] - common string functions](/img/95/58052b5d7a4a7d3e7891b22fd9f9c4.png)
[advanced C language] - common string functions

Teach you how to use code to realize SSO single sign on

蔚来缘何没有产品主义?

Basic database operations in MySQL

【古月21讲】ROS入门系列(2)——发布者Publisher、订阅者Subscriber的编程实现+自定义话题消息编程实现

拓扑排序原理
![[mathematical modeling summer training] CUMCM calendar year problem classification 2000-2021 digital modeling national competition problem and solution model](/img/42/1a9eb3ceb63e0191e8d19d89db4619.png)
[mathematical modeling summer training] CUMCM calendar year problem classification 2000-2021 digital modeling national competition problem and solution model

Spark Tuning (VI): it's really good to be nice to everyone -- broadcast variables
随机推荐
PLC approximately calculates the water tank flow (FC) through Bernoulli equation
Modern data stack: develop data efficiently and assist enterprise decision-making
BeautifulSoap基本使用
Introduction to Kali system use of hping3
oracledb_ Exporter monitors Oracle, a very low intrusive monitoring scheme.
Serein [lazy artifact] a graphical tool that collects URLs in batches and detects the collected URLs in batches. It solves the problem of fishing project
Dlvm netcore open source Framework
Super sub query implements join query gracefully
[Gu Yue 21 talks] ROS introduction series (2) -- programming implementation of publisher and subscriber + programming implementation of customized topic message
Spike project learning
kali系统入门-Hping3的使用
Pytest+request+allure+excel interface automatic construction from 0 to 1 [three package request]
MacM1芯片,centos8虚拟机安装mysql8,服务起来了,登录报错
Nvisual API interface instructions
Four thinking abilities that front-line technicians should pay attention to
美团一面:@Transactional 原理和常见的坑?
Jmeter正则表达获取登录token
疑似被Apple招安,PlayCover作者删库跑路
[mathematical modeling summer training] CUMCM calendar year problem classification 2000-2021 digital modeling national competition problem and solution model
The most common algorithm interview questions