unit DateTimePickerBorderless;
interface
uses
System.SysUtils, System.Classes,
Vcl.Controls,
Vcl.ComCtrls,
Vcl.Graphics,
Winapi.Messages,
Winapi.Windows;
type
TDateTimePickerBorderless =
class(TDateTimePicker)
private
{ Private declarations }
FInnerBorderColor: TColor;
FOuterBorderColor: TColor;
procedure WMPaint (
var Message: TWMPaint);
message WM_PAINT;
procedure SetInnerBorderColor(
const Value: TColor);
procedure SetOuterBorderColor(
const Value: TColor);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
Override;
published
{ Published declarations }
property InnerBorderColor: TColor
read FInnerBorderColor
Write SetInnerBorderColor;
property OuterBorderColor: TColor
read FOuterBorderColor
Write SetOuterBorderColor;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
emarti', [TDateTimePickerBorderless]);
end;
{ TDateTimePickerBorderless }
constructor TDateTimePickerBorderless.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ParentColor:= false;
FInnerBorderColor:= clWhite;
FOuterBorderColor:= clWhite;
end;
destructor TDateTimePickerBorderless.Destroy;
begin
inherited;
end;
procedure TDateTimePickerBorderless.SetInnerBorderColor(
const Value: TColor);
begin
FInnerBorderColor:= Value;
Invalidate;
end;
procedure TDateTimePickerBorderless.SetOuterBorderColor(
const Value: TColor);
begin
FOuterBorderColor:= Value;
Invalidate;
end;
procedure TDateTimePickerBorderless.WMPaint(
var Message: TWMPaint);
var
OuterBrush, InnerBrush: HBRUSH;
DC: hdc;
R: TRect;
begin
inherited;
DC:= GetWindowDC(
Handle);
try
OuterBrush:= CreateSolidBrush(FOuterBorderColor);
InnerBrush:= CreateSolidBrush(FInnerBorderColor);
try
GetWindowRect(
Handle, R);
OffsetRect(R, -R.Left, -R.Top);
FrameRect(
DC, R, OuterBrush);
InflateRect(R, -1, -1);
FrameRect(
DC, R, OuterBrush) ;
InflateRect(R, -1, -1);
FrameRect(
DC, R, InnerBrush);
finally
DeleteObject(InnerBrush);
DeleteObject(OuterBrush);
end;
finally
ReleaseDC(
Handle,
DC);
end;
end;
end.