根据输入的文本自动包装一个编辑框. [英] wrap a edit box automatically according to a entered text .
本文介绍了根据输入的文本自动包装一个编辑框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个编辑框,我想像自动调整选项一样.意味着如果我输入长文本,则编辑框的长度也会增加.如果文本较小,则文本框的长度应减小.
我正在使用VC ++/MFC.
在此先感谢
解决方案
您可以使用DrawText
并将DT_CALCRECT
放在nFormat
中.这样可以提供所需的宽度和高度,并可以相应地更新编辑框(例如,在每个按键事件上).
http://msdn.microsoft.com/en-us/library/a6x7y2a4% 28VS.80%29.aspx [ ^ ]
祝你好运!
E.F. Nijboer是对的.您可以在对话框中处理EN_CHANGE事件,例如:
void CYourDlg::OnEnChangeEdit1() { CWnd* pWnd = GetDlgItem(IDC_EDIT1); //get the text CString text; pWnd->GetWindowText(text); //get the box size CRect boxRect; pWnd->GetWindowRect(boxRect); //get a temporary DC to compute text size CDC* pDC = pWnd->GetDC(); //compute text size CRect textRect = boxRect; pDC->DrawText(text, textRect, DT_CALCRECT); //release temporary DC pWnd->ReleaseDC(pDC); //update the box width pWnd->SetWindowPos(NULL, 0, 0, textRect.Width(), boxRect.Height(), SWP_NOMOVE | SWP_NOZORDER); }
hi
i have one edit box i want do like autofit option. means if i enter long text the editbox length also increase. if text is small text box length should decrease.
i am using VC++/MFC.
thanks in advance
解决方案
You can useDrawText
and putDT_CALCRECT
innFormat
. This gives you the width and height needed and can update the editbox accordingly (for example on each key press event).
http://msdn.microsoft.com/en-us/library/a6x7y2a4%28VS.80%29.aspx[^]
Good luck!
E.F. Nijboer is right. You can handle the EN_CHANGE event in your dialog for example:
void CYourDlg::OnEnChangeEdit1() { CWnd* pWnd = GetDlgItem(IDC_EDIT1); //get the text CString text; pWnd->GetWindowText(text); //get the box size CRect boxRect; pWnd->GetWindowRect(boxRect); //get a temporary DC to compute text size CDC* pDC = pWnd->GetDC(); //compute text size CRect textRect = boxRect; pDC->DrawText(text, textRect, DT_CALCRECT); //release temporary DC pWnd->ReleaseDC(pDC); //update the box width pWnd->SetWindowPos(NULL, 0, 0, textRect.Width(), boxRect.Height(), SWP_NOMOVE | SWP_NOZORDER); }
这篇关于根据输入的文本自动包装一个编辑框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文