简体   繁体   English

如何更改编辑控件的文本?

[英]How change edit control's text?

I have a button and text control in MFC dialog window, when I click on button, in edit control must be replaced for example "hello world" . 我在MFC对话框窗口中有一个按钮和文本控件,当我单击按钮时,必须替换编辑控件,例如"hello world"
but if I write 但是如果我写

edit="hello wordl"

it doesn't change, how can I change? 它没有改变, 我该如何改变?

First you should add a variable to edit.To do that right click on the edit and choose Add Variable... in Add Member variable Wizard change Category from Control to Value after that in the Variable name field type a name like m_EditValue then click finish.from now you can change the Edit Control simply by following code. 首先,您应该添加一个变量进行编辑。右键单击编辑,然后在Add Member variable Wizard选择添加变量..., Add Member variable Wizard类别从Control更改为Value ,然后在变量名称字段中输入名称,例如m_EditValue然后单击完成从现在开始,您只需按照以下代码即可更改“编辑控件”。

   void CAboutDlg::OnBnClickedButton1()
    {
        // TODO: Add your control notification handler code here
        m_EditValue = L"Hello World";
        UpdateData(FALSE);
    }

使用SetWindowText方法:

edit.SetWindowText( _T("Hello, World!") );

First you need a CEdit member variable of the dialog. 首先,您需要对话框的CEdit成员变量。 Use 'Add Variable' in the dialog editor. 在对话框编辑器中使用“添加变量”。 If you name this variable m_helloedit then in your button click function 如果您将此变量m_helloedit则在您的按钮中单击函数

m_helloedit.SetWindowText(_T("hello world!"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM