ComboBox文本居中/给ComboBox加上Alignment属性(50分)

揽月

Unregistered / Unconfirmed
GUEST, unregistred user!
要使ComboBox文本居中或者给ComboBox加上Alignment属性,是否需要重载WndProc,并且要重写WMPaint?具体怎么实现,请教大家。
 

天道酬勤

Unregistered / Unconfirmed
GUEST, unregistred user!
重写CreateParams应该就可以吧
我重写了TEDIT
procedure TZEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
case FAlignment of
taRightjustify: params.style := params.style or es_right;
taLeftjustify : params.style := params.style or es_left;
taCenter : params.style := params.style or es_center;
end;

end;
 

揽月

Unregistered / Unconfirmed
GUEST, unregistred user!
重载CreateParams是不行的,对TEdit可以,但是对TComboBox不行,我试过了。
 
S

sunnyboy_delphi

Unregistered / Unconfirmed
GUEST, unregistred user!
cobobox style csOwnerDrawFixed
procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
Index: Integer;
Rect: TRect;
State: TOwnerDrawState);
var i:integer;
begin

i:=(combobox1.Width-combobox1.Canvas.TextWidth(combobox1.Items[index])) div 2;
combobox1.Canvas.TextRect(rect,Rect.Left+i ,rect.Top,combobox1.Items[index]);
end;
 
S

sunnyboy_delphi

Unregistered / Unconfirmed
GUEST, unregistred user!
这个是画上的 自己调好了就ok 了
CreateParams combobox 不可以
 
X

XF.Lian

Unregistered / Unconfirmed
GUEST, unregistred user!
自画才行 支持楼上的
 

Similar threads

回复
0
查看
623
不得闲
D
回复
0
查看
518
DelphiTeacher的专栏
D
顶部