实现编辑框文本对齐方式
如何使TEDIT控件中的TEXT显示在控件的中间或下面(一般在上面),
像TLABEL中的LAYOUT至为CENTER一样
var
Rct: TRect;
begin
Rct := edit1.ClientRect;
Inc(Rct.Top, 3);
sendmessage(edit1.handle, EM_SETRECT, 0, Integer(@Rct)); end;
EM_SETRECT 只对于 Multiline Edit 有效, :-)
An application sends an EM_SETRECT message to set the formatting
rectangle of a
multiline edit control.
换成 Memo 就可以了。
procedure TForm1.Button2Click(Sender: TObject); var
Rct: TRect;
begin
SendMessage(Memo1.Handle, EM_GETRECT, 0, Integer(@Rct));
Inc(Rct.Top, 5);
SendMessage(Memo1.Handle, EM_SETRECT, 0, Integer(@Rct)); end;
那也简单, 那些语句前加一句
SetWindowLong(edit.Handle,GWL_STYLE, GetWindowLong(edit.Handle, GWL_STYLE) or ES_MULTILINE);
不过需要多写个OnKeyPress事件过滤掉输入的回车符.
最好自己继承TEdit做个有这功能的控件.