当我在对话框窗口中按下按钮时,如何在该对话框中更改/添加编辑控制框的文本 [英] How to change/append the text of edit control box in that dialog when i pressed the push button in dialog window

查看:93
本文介绍了当我在对话框窗口中按下按钮时,如何在该对话框中更改/添加编辑控制框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于对话框的vc ++/MFC应用程序来做计算器程序.在一个对话框中,我添加了一个编辑文本控件和一个按钮.因此,当我单击对话框上的按钮时,需要在该对话框中更改/添加编辑控制框的文本.要显示文本,请使用ButtonClicked方法中的Setsel()和ReplaceSel()方法,但无法正常工作.

I am doing calculator program by using dialog based vc++/MFC application. In a dialog box, I added a edit text control and a push button. So I need to change/append the text of the edit control box in that dialog when I click the button on the dialog. To display the text am using Setsel() and ReplaceSel() methods in ButtonClicked method, but it's not working.

显示代码的相关部分,并讲解相关内容.

Show the relevant portion of your code and relevent artical.

basu

推荐答案

如果您要做的就是在CEdit控件中显示一些文本,那么为什么不使用它呢?

If all you want to do is display some text in a CEdit control then why not use it's SetWindowText function?

以下内容使用您的SetSel/ReplaceSel方法替换内容:

The following replaces the contents using your SetSel/ReplaceSel method:

void CTextCtrlAddDlg::OnBnClickedButton1()
{
    int start = 0;
    int end = m_editControl.GetWindowTextLength();
    m_editControl.SetSel(start, end);
    m_editControl.ReplaceSel(L"Test");
}

...,其中m_editControl是编辑控件.如果要在文本末尾附加文字,只需将选择内容设置在末尾即可:

...where m_editControl is the edit control. If you want to append the text at the end, simply set the selection to the end:

void CTextCtrlAddDlg::OnBnClickedButton1()
{
    int end = m_editControl.GetWindowTextLength();
    m_editControl.SetSel(end, end);
    m_editControl.ReplaceSel(L"Test");
}

不过,我同意Goz的观点;一些示例代码frmo,可以帮助我们确定对您不起作用的内容.

I agree with Goz though; some example code frmo you would help us identify what isn't working for you.

这篇关于当我在对话框窗口中按下按钮时,如何在该对话框中更改/添加编辑控制框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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