当只读属性设置为TRUE时,无法清除cedit中的文本 [英] Unable to clear the text in cedit when read only property is set to TRUE

查看:170
本文介绍了当只读属性设置为TRUE时,无法清除cedit中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC对话框上有一个CEdit(编辑控件)。



我已将控件的只读属性设置为TRUE。我正在为该控件编写流程输出。单击重置按钮时,需要清除文本。



我尝试过:



我用以下代码清除了文字。



m_txtProcessOutput.SetWindowTextA();



但这并没有清除文本。



我尝试将Read-Only属性设置为FALSE。然后文本被清除。但是文本框必须是只读的。



当点击重置按钮时,我也尝试了下面的代码。



m_txtProcessOutput.SetReadOnly(0);

m_txtProcessOutput.SetWindowTextA();

m_txtProcessOutput.SetReadOnly(1);





但这并没有锻炼。任何建议都表示赞赏。

I have an CEdit (Edit control) on MFC dialog.

I have set the 'Read-Only' property of the control as TRUE. I am writing a process output to that control. When 'Reset' button is clicked, the text need to be cleared.

What I have tried:

I have used the below code to clear the text.

m_txtProcessOutput.SetWindowTextA("");

But this did not cleared the text.

I have tried setting the Read-Only property to FALSE. Then text is cleared. But the text box need to be Read-Only.

I have tried the below code also when 'Reset' button is clicked.

m_txtProcessOutput.SetReadOnly(0);
m_txtProcessOutput.SetWindowTextA("");
m_txtProcessOutput.SetReadOnly(1);


But this did not workout. Any suggestion is appreciated.

推荐答案

解决方案。



使用以下代码。



CRect rect;

m_txtProcessOutput.SetWindowTextA();

m_txtProcessOutput.GetWindowRect(&rect);

ScreenToClient(&rect);

InvalidateRect(&rect);

UpdateWindow();
Got the solution.

Used the below code.

CRect rect;
m_txtProcessOutput.SetWindowTextA("");
m_txtProcessOutput.GetWindowRect(&rect);
ScreenToClient(&rect);
InvalidateRect(&rect);
UpdateWindow();


这篇关于当只读属性设置为TRUE时,无法清除cedit中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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