Radio之谈---vc++

 

1)程序一运行就Radio按钮就被选择中,只需在OnInitDialog()添加如下代码

 CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1);
  tb->SetCheck(1);

代表IDC_RADIO1被选中。

 

2)获取Radio选中的值:

先定义一个全局变量 int m_Radio;或者在class CRadioDlg : public CDialog
{

int m_Radio

}(这里的类在头文件那里的)

也是可以的;然后在Radio选择事件里面:

void CRadioDlg::OnRadio1()
{
 // TODO: Add your control notification handler code here
 m_Radio=1;
}

void CRadioDlg::OnRadio2()
{
 // TODO: Add your control notification handler code here
 m_Radio=2;
}

void CRadioDlg::OnRadio3()
{
 // TODO: Add your control notification handler code here
 m_Radio=3;
}

void CRadioDlg::OnRadio4()
{
 // TODO: Add your control notification handler code here
 m_Radio=4;
}

最后在一个获取Radio控件选择中的值,如按钮单击事件里面:

void CRadioDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 CString str1;
    CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1+m_Radio-1);
 tb->GetWindowText(str1);
 m_Static.SetWindowText(str1);
 
}

最终运行的效果图:

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值