Поделиться через


CRichEditCtrl::LimitText

Limits the length of the text that the user can enter into an edit control.

void LimitText(
   long nChars = 0 
);

Параметры

  • nChars
    Specifies the length (in bytes) of the text that the user can enter. If this parameter is 0 (the default value), the text length is set to 64K bytes.

Заметки

Changing the text limit restricts only the text the user can enter. It has no effect on any text already in the edit control, nor does it affect the length of the text copied to the edit control by the SetWindowText member function in CWnd. If an application uses the SetWindowText function to place more text into an edit control than is specified in the call to LimitText, the user can delete any of the text within the edit control. However, the text limit will prevent the user from replacing the existing text with new text, unless deleting the current selection causes the text to fall below the text limit.

ПримечаниеПримечание.

For the text limit, each OLE item counts as a single character.

For more information, see EM_EXLIMITTEXT in the Windows SDK.

Пример

// Limit the number of characters to be the maximum number visible.

// Get the text metrics for the edit; needed for the
// average character width.
TEXTMETRIC tm;
CDC* pDC = m_myRichEditCtrl.GetDC();
pDC->GetTextMetrics(&tm);
m_myRichEditCtrl.ReleaseDC(pDC);

CRect r;
m_myRichEditCtrl.GetRect(&r);
m_myRichEditCtrl.LimitText(r.Width()/tm.tmAveCharWidth);

Требования

Header: afxcmn.h

См. также

Основные понятия

CRichEditCtrl Class

CRichEditCtrl Members

Hierarchy Chart

CRichEditCtrl::GetLimitText