mfc 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);

  }

  

温馨提示:答案为网友推荐,仅供参考
相似回答