unit uComboBoxExt;
{$mode objfpc}{$H+}
interface
uses
Classes, Windows, Messages, Controls, StdCtrls,Graphics;
type
{ TComboBoxExt }
TComboBoxExt = Class(TComboBox)
private
FCTextHint:string;
FRequired:boolean;
procedure WMPaint(var Message: TWMPaint); message WM_Paint;
procedure SetCTextHint(const Value:string);
protected
procedure WndProc(var Message:TMessage); override;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy; override;
property CTextHint:string read FCTextHint write SetCTextHint;
property Required:boolean read FRequired write FRequired Default False;
procedure PaintRedFrame;
end;
implementation
{ TComboBoxExt }
...
procedure TComboBoxExt.WndProc(var Message: TMessage);
var
R:TREct;
begin
inherited WndProc(Message);
if (Message.Msg = WM_PAINT) and (Text='') then begin
Canvas.Font := Font;
Canvas.Font.Color := clGray;
R:= ClientRect;
R.Left:=R.Left+5;
R.Top:=R.Top+2;
Canvas.TextRect(R,R.Left,R.Top,FCTextHint);
Canvas.TextOut(R.Left,R.Top,FCTextHint);
end;
if (FRequired=True) and (Text='') then PaintRedFrame;
with message do
case Msg of
WM_LButtonUp, WM_LButtonDown,
WM_KeyDown, WM_KeyUp, WM_SetFocus, WM_KillFocus,
CM_TextChanged:
begin
invalidate;
end;
end;
end;
...