• 透明Panel


    unit TransparentPanel;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
    type
      TTransparentPanelClass = class(TPanel)
      private
        procedure SetParent(AParent: TWinControl); override;
        procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_EraseBkGnd;
      protected
        procedure CreateParams(var Params: TCreateParams); override;
        procedure Paint; override;
      public
        constructor Create(AOwner: TComponent); override;
        procedure Invalidate; override;
      end;
    
    implementation
    constructor TTransparentPanelClass.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      ControlStyle := ControlStyle - [csOpaque];
    end;
    
    procedure TTransparentPanelClass.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
    end;
    
    //进行绘制
    procedure TTransparentPanelClass.Paint;
    begin
      Canvas.Brush.Style := bsClear;
      Canvas.Rectangle(0, 0, Width, Height);
      Canvas.TextOut(Width div 2, Height div 2, 'Transparent');
    end;
    
    procedure TTransparentPanelClass.WMEraseBkGnd(var Message: TWMEraseBkGnd);
    begin
      Message.Result := 1;
    end;
    
    procedure TTransparentPanelClass.SetParent(AParent: TWinControl);
    begin
      inherited SetParent(AParent);
      if Parent <> nil then
        SetWindowLong(Parent.Handle, GWL_STYLE, GetWindowLong
          (Parent.Handle, GWL_STYLE) and not WS_ClipChildren);
    end;
    
    procedure TTransparentPanelClass.Invalidate;
    var
      oRect: TRect;
    begin
      //重画
      oRect := BoundsRect;
      if (Parent <> nil) and Parent.HandleAllocated then
        InvalidateRect(Parent.Handle, @oRect, True)
      else
        inherited Invalidate;
    end;
    
    end.
  • 相关阅读:
    MS SQL Sever数据库还原
    IIS 7.5 配置伪静态
    黑马程序员-out和ref
    黑马程序员-结构
    黑马程序员-ReadInt
    黑马程序员-hashtable
    黑马程序员-冒泡排序
    黑马程序员-快速排序
    黑马程序员-for和foreach
    黑马程序员-集合和索引器
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/10595383.html
Copyright © 2020-2023  润新知