How to Fix the TComboBox Ctl3D Property Bug?
-
06-07-2021 - |
Domanda
This is an image from a TForm
where I have a TEdit
at top and a TComboBox
at down.
As you can see, the TEdit does not have the classic 3D border of the Windows controls default theme. That's because I set the Ctl3D property
of that component to False
. Then you see that the TComboBox has it's normal 3D border, but in this case I also set the Ctl3D property
of that component to False
, but it continues to show the 3D border.
It seems to be a Delphi bug at development level. How could I fix that at code?
After testing RRUZ answer, BevelKind=bkFlat
, this came:
I do not know why it was so different... and bizarre. :-/
Altri suggerimenti
I Found it:
We have to set:
BevelInner
to bvNone
;
BevelKind
to bkFlat
;
BevelOuter
to bvSpace
.
this is best way which support BidiMode
and resize; and can fill border with client color:
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;