FrozenSky's Studio (=・ω・=)

MFC EditCtrl控件文字垂直居中

2018-03-09
FrozenSky
C++

// EditControl文本垂直居中
RECT editRect;
GetDlgItem(IDC_EDIT_IP)->GetClientRect(&editRect);
OffsetRect(&editRect, 0, 4);
GetDlgItem(IDC_EDIT_IP)->SendMessage(EM_SETRECT, 0, (LPARAM)&editRect);

需要注意:EditControl控件必须启用多行模式

MSDN

EM_SETRECT message

Sets the formatting rectangle of a multiline edit control. The formatting rectangle is the limiting rectangle into which the control draws the text. The limiting rectangle is independent of the size of the edit control window.

This message is processed only by multiline edit controls. You can send this message to either an edit control or a rich edit control.

Parameters
wParam

Rich Edit 2.0 and later: Indicates whether lParam specifies absolute or relative coordinates. A value of zero indicates absolute coordinates. A value of 1 indicates offsets relative to the current formatting rectangle. (The offsets can be positive or negative.)

Edit controls and Rich Edit 1.0: This parameter is not used and must be zero.

lParam

A pointer to a RECT structure that specifies the new dimensions of the rectangle. If this parameter is NULL, the formatting rectangle is set to its default values.

Return value

This message does not return a value.


Similar Posts

Comments