⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlxtpanel1.pas

📁 进销存以及BOM管理,SQl Server数据库程序
💻 PAS
字号:
unit QLXTPanel1;

interface

uses
  SysUtils, Classes, QControls, QExtCtrls, Windows, Graphics, Controls,Extctrls;

type
  LXTPanel1 = class(TPanel)
  private
        FPicture : TPicture;
        FTransparent : Boolean;
        FAutoSize : Boolean;

        procedure PictureChanged(Sender: TObject);
        procedure SetPicture(const Value: TPicture);
        procedure SetAutoSize(const Value: Boolean); reintroduce;
        procedure SetTransparent(const Value: Boolean);
        procedure SetFont(const Value : TFont);
        procedure SetCaption(const Value : TCaption);
        procedure SetAlignment(const Value : TAlignment);

    protected
        procedure Paint(); override;

    public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy(); override;

    published
        property Picture : TPicture read FPicture write SetPicture;
        property Transparent : Boolean Read FTransparent Write SetTransparent default false;
        property AutoSize : Boolean Read FAutoSize Write SetAutoSize;

        property Font write SetFont;
        property Caption write SetCaption;
        property Alignment write SetAlignment;
    end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('liuxiangvcl', [LXTPanel1]);
end;

{ LXTPanel1 }

constructor LXTPanel1.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);

    FPicture := TPicture.Create();
    FPicture.OnChange := PictureChanged;

    Repaint();
end;

destructor LXTPanel1.Destroy;
begin
    FPicture.Free();
    FPicture := nil;

    inherited;
end;

procedure LXTPanel1.Paint;
const
    Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
    Flags: Longint;
    Rect: TRect;
    FontHeight: Integer;
begin
    Canvas.Brush.Style := bsClear;
    Canvas.Font := Font;

    if Assigned(FPicture.Graphic) then
    begin
        if FAutoSize then
        begin
            Width := FPicture.Width;
            Height := FPicture.Height;
        end;

        if FPicture.Graphic.Transparent <> FTransparent then
            FPicture.Graphic.Transparent := FTransparent;
        Canvas.StretchDraw(ClientRect, FPicture.Graphic);
    end
    else
    begin
        Canvas.Brush.Color := Color;
        Canvas.FillRect(ClientRect);
    end;

    if Caption <> '' then
    begin
        Rect := GetClientRect;
        FontHeight := Canvas.TextHeight('W');
        Rect.Top := ((Rect.Bottom + Rect.Top) - FontHeight) div 2;
        Rect.Bottom := Rect.Top + FontHeight;

        Flags := DT_EXPANDTABS or DT_VCENTER or Alignments[Alignment];
        Flags := DrawTextBiDiModeFlags(Flags);
        DrawText(Canvas.Handle, PChar(Caption), -1, Rect, Flags);
    end;
end;

procedure LXTPanel1.PictureChanged(Sender: TObject);
begin
   RePaint();
end;

procedure LXTPanel1.SetAlignment(const Value: TAlignment);
begin
    inherited Alignment := Value;

    Repaint();
end;

procedure LXTPanel1.SetAutoSize(const Value: Boolean);
begin
    FAutoSize := Value;

    RePaint();
end;

procedure LXTPanel1.SetCaption(const Value: TCaption);
begin
    inherited Caption := Value;

    Repaint();
end;


procedure LXTPanel1.SetFont(const Value: TFont);
begin
    inherited Font := Value;

    Repaint();
end;


procedure LXTPanel1.SetPicture(const Value: TPicture);
begin
    FPicture.Assign(Value);

    Repaint();
end;

procedure LXTPanel1.SetTransparent(const Value: Boolean);
begin
    FTransparent := Value;

    Repaint();
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -