禁用Radiobutton事件的控件 [英] Disable controls on Radiobutton event

查看:828
本文介绍了禁用Radiobutton事件的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将开发基于mfc对话的应用程序,其中一个场景有3个单选按钮;每当用户点击第3个单选按钮时,对话框上的某些控件应该被禁用!我怎么能这样做?

I am going to develop mfc dialogue based application in which one scenario there is 3 radio buttons; whenever user click on the 3rd radio button, some controls on the dialog should be disable!!! How can I do that??

推荐答案

为所有单选按钮添加 BN_CLICKED 处理程序以检测状态变化。从处理程序中,根据按钮状态启用或禁用相关控件。在你的场景中,一个函数可以处理所有这些:

Add BN_CLICKED handlers for all radio buttons to detect state changings. From within the handler, enable or disable dependant controls according to the button states. With your scenario, one function can handle it all:
// Handler function declared in header as 
//  afx_msg void OnBnClickedRadio();

ON_BN_CLICKED(IDC_RBTN_1, OnBnClickedRadio)
ON_BN_CLICKED(IDC_RBTN_2, OnBnClickedRadio)
ON_BN_CLICKED(IDC_RBTN_3, OnBnClickedRadio)

void CMyDialog::OnBnClickedRadio()
{
    // Enable controls if radio button 3 is not checked
    CButton *pRadio3 = (CButton*)GetDlgItem(IDC_RBTN_3);
    BOOL bEnable = (BST_CHECKED != pRadio3->GetCheck());
    // Access control by ID
    GetDlgItem(IDC_SOME_CONTROL)->EnableWindow(bEnable);
    // Access control by member var
    m_SomeOtherControl.EnableWindow(bEnable);
}


这篇关于禁用Radiobutton事件的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆