如何在MFC中禁用编辑控件 [英] How do I disable edit control in MFC

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

问题描述

Hi;

I have an edit control that takes string input from user and a CButton 'Record' to record that input. I want to catch the control and disable it when the user input is empty. I want to make sure that this enable/diable happens with the click of CButton.


void CCTRL::OnBnClicked() // code for Cbutton
{   
CString txt;    
if(!end)    
{       
IsCorrect(s); // comparing and checking user input     
m_input.SetCheck(0);       
if(Check())     
Run();  
} 
    

}


IsCorrect() is where user input is checked and compared with correct text.



编辑控件是受时间驱动的,需要先禁用一段时间,然后用户才能再次单击它.

在显示控件之前,一旦某些文本输入到编辑控件中,cbutton可能会被禁用并变为启用状态.
等待建议.

预先感谢.



The edit control is time driven and need to be disabled for a certain time before user can again click it.

Could it be possible that before display of control, cbutton is disabled and becomes enable once some text is input into edit control.
Waiting for suggestions.

Thanks in advance.

推荐答案

我相信您正在寻找的是.EnableWindow()方法.

例如:
I believe what you are looking for is the .EnableWindow() method.

example:
m_someControlVariable.EnableWindow(TRUE);




or

m_someControlVariable.EnableWindow(FALSE);


好,您的问题对我来说还不是很清楚.让我们看看是否可以解决它.

您有一个按钮和一个编辑控件.

1)您希望在编辑控件为空时禁用按钮,否则请启用.

2)您希望在单击按钮后的一段时间内禁用编辑控件.

您已经知道如何启用/禁用控件.

对于#2,您将需要使用计时器. 此处 [ CWnd :: GetWindowText [^ ]或 CWnd :: GetWindowTextLength [
OK, your question isn''t all that clear to me. Let''s see if I can sort it out.

You have a button and an edit control.

1) You want the button disabled when the edit control is empty, enabled otherwise.

2) You want the edit control disabled for some time period after the button is clicked.

You already know how to enable/disable a control.

For #2 you will want to use a timer. Here[^] is some information.

For #1, it sounds to me like you already know about CEdit''s ON_EN_CHANGE message handler. You would derive a new class from CEdit implementing such a message handler and include it in the message map for that class.

You would then use an instance of that class for your edit control. How you do that depends on how you are creating the control in the first place.

To check if the edit control is empty, have you considered using CWnd::GetWindowText[^] or CWnd::GetWindowTextLength[^] ?


@kinar
我知道此方法,但我想将其与某些控件(如ONEnUpdate()或ONEnChange())绑定,在其中可以使用某些if语句,如

@kinar
I know this method but I want to bind it with some control like ONEnUpdate() or ONEnChange() where I can use some if statement like

<br />
if (str!="")<br />
{<br />
m_an.EnableWindow(TRUE)<br />
}<br />
else<br />
{


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

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