» Help

How to create a borderless TComboBox

   
Question
Is it possible to create a flat or borderless combo box? If so, how would I go about it?
{ ... }
TNoBorderComboBox = class(TComboBox)
  protected
    procedure WMPaint(var Msg: TMessage); message WM_PAINT;
  end;

procedure TNoBorderComboBox.WMPaint(var Msg: TMessage);
var
  C: TControlCanvas;
  R: TRect;
begin
  inherited;
  C := TControlCanvas.Create;
  try
  C.Control := Self;
  with C do
  begin
    Brush.Color := clBtnFace;
    R := ClientRect;
    FrameRect(R);
    InflateRect(R, - 1, - 1);
    FrameRect(R);
    end;
  finally
    C.Free;
  end;
end;
Original resource: The Delphi Pool
Author: Xavier Pacheco
Added: 2009-08-24
Last updated: 2009-08-24

« Return to contents »