Einzelnen Beitrag anzeigen

Headbucket

Registriert seit: 12. Dez 2013
Ort: Dresden
172 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

AW: DateTimePicker ohne Border

  Alt 17. Mär 2017, 09:46
Hallo,

da gibt es meines Wissens nach (noch) keine simple Lösung. Man kommt also wohl leider nicht um das Selbstzeichnen herum.

Folgenden Code habe ich z.B. hier gefunden: http://dxdelphi.blogspot.de/2016/04/...rame-from.html

Delphi-Quellcode:
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.
Grüße
Headbucket
  Mit Zitat antworten Zitat