MFC应用实例:[35]Radio Button实现单选
1、新建一个基于对话框的应用程序,工程名为RadioButton。
2、如下图为对话框添加三个Radio Button。
3、为CRadioButtonDlg类添加颜色变量,记录当前背景颜色。
4、添加三个Radio Button的响应函数。
void CRadioButtonDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_BKColor = RGB(255,0,0);
Invalidate();
}
void CRadioButtonDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_BKColor = RGB(0,255,0);
Invalidate();
}
void CRadioButtonDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
m_BKColor = RGB(0,0,255);
Invalidate();
}
5、改写CRadioButtonDlg类的OnPaint()函数
void CRadioButtonDlg::OnPaint()
{
CRect rect;
CPaintDC dc(this);
GetClientRect(rect);
dc.FillSolidRect(rect,m_BKColor);
}
6、程序运行如下:
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:124
阅读量:182
阅读量:42
阅读量:157
阅读量:145