这是支持BidiMode
和调整大小的最佳方式;并且可以用客户端颜色填充边框:
TTestComboBox=class(TComboBox)
protected
procedure WMPaint(var Msg: TMessage); message WM_Paint;
End;
Procedure TTestComboBox.WMPaint(var Msg: TMessage);
var MCanvas: TControlCanvas;
R: TRect;
Begin
inherited;
MCanvas:=TControlCanvas.Create;
Try
MCanvas.Control:=Self;
With MCanvas do begin
R:=ClientRect;
Brush.Style:= bsClear;
Pen.Color:= Color;
Pen.Width:= 3;
if BiDiMode in [bdRightToLeft, bdRightToLeftNoAlign] then begin
if Style = csSimple then //remove border and space
Rectangle(1, 1, R.Width - 1, R.Height-1) else Rectangle(-1, 1, R.Width, R.Height-1);
if Style in [csDropDown, csOwnerDrawFixed, csOwnerDrawVariable] then begin
Pen.Width:= 5; //remove space btw editor and button
MoveTo(18, 0);
LineTo(18, R.Height-1);
end;
end else begin
if Style = csSimple then
Rectangle(1, 1, r.Width - 1, R.Height-1) else Rectangle(1, 1, r.Width + 1, R.Height-1);
if Style in [csDropDown, csOwnerDrawFixed, csOwnerDrawVariable] then begin
Pen.Width:= 5;
MoveTo(R.Width - 18, 0);
LineTo(R.Width - 18, R.Height-1);
end;
end;
end;
finally
MCanvas.Free;
End;
End;