【问题标题】:How change edit control's text?如何更改编辑控件的文本?
【发布时间】:2013-05-19 23:04:04
【问题描述】:

我在 MFC 对话窗口中有一个按钮和文本控件,当我单击按钮时,必须替换编辑控件,例如 "hello world"
但是如果我写

edit="hello wordl"

它没有改变,我该如何改变?

【问题讨论】:

    标签: c++ button text mfc


    【解决方案1】:

    首先,您应该添加一个要编辑的变量。为此,请右键单击编辑并选择添加变量... in Add Member variable Wizard 将类别从 Control 更改为 Value,然后在变量名称字段中键入 a名称如m_EditValue 然后单击完成。从现在您可以通过以下代码更改编辑控件。

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

    【讨论】:

      【解决方案2】:

      使用SetWindowText 方法:

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

      【讨论】:

        【解决方案3】:

        首先你需要一个对话框的 CEdit 成员变量。在对话框编辑器中使用“添加变量”。如果您将此变量命名为m_helloedit,那么在您的按钮单击功能中

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-27
          • 1970-01-01
          • 2011-11-03
          • 2010-10-15
          • 1970-01-01
          相关资源
          最近更新 更多