MFC中 编辑框输入换行功能

时间:2023-03-09 22:07:50
MFC中 编辑框输入换行功能

首先修改编辑框的属性:

Multiline 设为true ,

Auto HScroll 设为true ,

Auto VScroll 设为 true 。

然后响应PreTranslateMessage(MSG* pMsg)这个消息,截获回车键。如图:

MFC中 编辑框输入换行功能

从中可以看出,只需添加下面三行:

m_editPoemFile.SetSel(-1,-1);         //自动滚屏

m_editPoemFile.ReplaceSel(L"\r\n" );   //换行

UpdateData(true);

// 其中m_editPoemFile 为编辑框的控制变量。