Delphi 带实心边框的透射式面板

Delphi 带实心边框的透射式面板,delphi,Delphi,下面是一个透明面板vcl 它起作用了 但我希望绘制实体边界(其他部分仍然是透明的) 有什么提示吗 欢迎您的评论 unit aframek; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TAframekStyle = (

下面是一个透明面板vcl

它起作用了

但我希望绘制实体边界(其他部分仍然是透明的)

有什么提示吗

欢迎您的评论

unit aframek;

interface   

uses           
    Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,   
    ExtCtrls;

type
    TAframekStyle   =   (
        gsBlackness,   gsDstInvert,   gsMergeCopy,   gsMergePaint,   gsNotSrcCopy,   
        gsNotSrcErase,   gsPatCopy,   gsPatInvert,   gsPatPaint,   gsSrcAnd,   
        gsSrcCopy,   gsSrcErase,   gsSrcInvert,   gsSrcPaint,   gsWhiteness);   

    TAframek   =   class(TCustomControl)
    private   
        FColor:   TColor;   
        FStyle:   TAframekStyle;
        FOnPaint:   TNotifyEvent;


        procedure   SetColor(Value:   TColor);   
        procedure   SetStyle(Value:   TAframekStyle);
        procedure   CMCtl3DChanged(var   Message:   TMessage);   message   CM_CTL3DCHANGED;
        procedure   WMEraseBkgnd(var   Message:   TMessage);   message   WM_ERASEBKGND;   
        procedure   WMWindowPosChanging(var   Message:   TWMWindowPosChanging);   message   WM_WINDOWPOSCHANGING;   
    protected   
        Buffer:   TBitmap;   

        procedure   CreateParams(var   Params:   TCreateParams);   override;   
        procedure   Paint;   override;   
        procedure   Resize;   override;   
    public   
        constructor   Create(AOwner:   TComponent);   override;   
        destructor   Destroy;   override;   
        property   Canvas;   

    published


        property   Align;
        property   Anchors;
        property   AutoSize;   
        property   BiDiMode;   
        property   BorderWidth;   
        property   Color:   TColor   read   FColor   write   SetColor;   
        property   Ctl3D;   
        property   Enabled;   
        property   Style:   TAframekStyle   read   FStyle   write   SetStyle   default   gsSrcAnd;
        property   Visible;   

        property   OnClick;   
        property   OnDblClick;   
        property   OnEnter;
        property   OnExit;   
        property   OnMouseDown;   
        property   OnMouseMove;   
        property   OnMouseUp;   
        property   OnResize;   
        property   OnPaint:   TNotifyEvent   read   FOnPaint   write   FOnPaint;
    end;   

procedure   Register;   

implementation   

procedure   Register;   
begin   
    RegisterComponents('aka',   [TAframek]);
end;   

function   AframekStyleToInt(gs:   TAframekStyle):   LongInt;
begin   
    case   gs   of   
        gsBlackness     :   Result   :=   cmBlackness;
        gsDstInvert     :   Result   :=   cmDstInvert;   
        gsMergeCopy     :   Result   :=   cmMergeCopy;   
        gsMergePaint   :   Result   :=   cmMergePaint;   
        gsNotSrcCopy   :   Result   :=   cmNotSrcCopy;   
        gsNotSrcErase:   Result   :=   cmNotSrcErase;   
        gsPatCopy         :   Result   :=   cmPatCopy;   
        gsPatInvert     :   Result   :=   cmPatInvert;   
        gsPatPaint       :   Result   :=   cmPatPaint;   
        gsSrcAnd           :   Result   :=   cmSrcAnd;   
        gsSrcCopy         :   Result   :=   cmSrcCopy;   
        gsSrcErase       :   Result   :=   cmSrcErase;   
        gsSrcInvert     :   Result   :=   cmSrcInvert;   
        gsSrcPaint       :   Result   :=   cmSrcPaint;   
        gsWhiteness     :   Result   :=   cmWhiteness;   
        else                       Assert(True,   'Error   parameter   in   function   AframeStyleToInt');
    end;   
end;   

constructor   TAframek.Create(AOwner:   TComponent);
var

    FMarkBrush: LOGBRUSH;
    FMarkPen: HPEN;
    FPenStyle: array[0..1] of Integer;
    FStartAngle: Single;

begin   
    inherited   Create(AOwner);   
    Buffer   :=   TBitmap.Create;
    ControlStyle   :=   [csAcceptsControls,   csCaptureMouse,   csClickEvents,   
        csDoubleClicks,   csReplicatable];   
    Width   :=   100;   
    Height   :=   100;   
    FStyle   :=   gsSrcAnd;   
    ParentCtl3d   :=   False;   
    Ctl3D   :=   False;   
    ParentColor   :=   False;   
    FColor   :=   clWhite;



end;   

destructor   TAframek.Destroy;
begin   
    Buffer.Free;   
    inherited   Destroy;   
end;   

procedure   TAframek.Paint;
var   
    R:   TRect;   
    rop:   LongInt;   
begin   
    R   :=   Rect(0,   0,   Width,   Height);   
    Buffer.Width   :=   Width;   
    Buffer.Height   :=   Height;   
    Buffer.Canvas.Brush.Style   :=   bsSolid;   
    Buffer.Canvas.Brush.Color   :=   FColor;   
    Buffer.Canvas.FillRect(Rect(0,   0,   Width,   Height));   
    rop   :=   AframekStyleToInt(FStyle);
    StretchBlt(Buffer.Canvas.Handle,   0,   0,   Width,   Height,   
                          Canvas.Handle,   0,   0,   Width,   Height,   rop);   
    if   Ctl3D   then   DrawEdge(Buffer.Canvas.Handle,   R,   BDR_RAISEDINNER,   BF_RECT);   
    Buffer.Canvas.Pen.Mode   :=   pmCopy;   
    Buffer.Canvas.Pen.Style   :=   psSolid;   
    Canvas.Draw(0,   0,   Buffer);   
    if   Assigned(FOnPaint)   then   FOnPaint(Self);   
end;   


procedure   TAframek.SetColor(Value:   TColor);
begin   
    if   Value   <>   FColor   then   
    begin   
        FColor   :=   Value;   
        RecreateWnd;   
    end;   
end;   

procedure   TAframek.CreateParams(var   Params:   TCreateParams);
begin   
    inherited   CreateParams(Params);   

    Params.ExStyle   :=   Params.ExStyle   +   WS_EX_TRANSPARENT;   
end;   

procedure   TAframek.WMWindowPosChanging(var   Message:   TWMWindowPosChanging);
begin   
    Invalidate;   

    inherited;   
end;   

procedure   TAframek.WMEraseBkgnd(var   Message:   TMessage);
begin   
    Message.Result   :=   0;   
end;   

procedure   TAframek.Resize;
begin   
    Invalidate;   

    inherited;   
end;   

procedure   TAframek.CMCtl3DChanged(var   Message:   TMessage);
begin   
    inherited;   

    RecreateWnd;   
end;   

procedure   TAframek.SetStyle(Value:   TAframekStyle);
begin   
    if   Value   <>   FStyle   then   
    begin   
        FStyle   :=   Value;   
        RecreateWnd;   
    end;   
end;   

end.
unitaframek;
接口
使用
窗口、消息、系统工具、类、图形、控件、窗体、对话框、,
ExtCtrls;
类型
TAframekStyle=(
gsBlackness、gsDstInvert、gsMergeCopy、gsMergePaint、gsNotSrcCopy、,
GSNOTSCREASE、gsPatCopy、gsPatInvert、gsPatPaint、gsSrcAnd、,
GSSRCOPY、gsSrcErase、GSSRCInter、GSSRCPRAINT、GSSRWhiteness);
TAframek=class(TCustomControl)
私有的
f颜色:t颜色;
FStyle:takstyle;
FOnPaint:TNotifyEvent;
程序SetColor(值:TColor);
程序设置样式(值:TAframekStyle);
程序CMCtl3DChanged(变量消息:TMessage);消息CM_ctl3d已更改;
程序WMEraseBkgnd(var消息:TMessage);消息WM_ERASEBKGND;
过程WMWindowPosChanged(var消息:TWMWINDOWPOSCHING);消息WM_WINDOWPOSCHANGING;
受保护的
缓冲区:TBitmap;
过程CreateParams(变量参数:TCreateParams);推翻
程序漆;推翻
程序调整;推翻
公开的
构造函数创建(AOwner:TComponent);推翻
毁灭者毁灭;推翻
财产画布;
出版
属性对齐;
地产锚;
属性自动调整大小;
比迪莫德财产;
属性边界宽度;
属性颜色:TColor read FColor write SetColor;
属性Ctl3D;
启用属性;
属性样式:TAframekStyle read FStyle write SetStyle default gsSrcAnd;
有形财产;
属性OnClick;
属性单击;
财产所有权人;
不动产退出;
房地产价格下跌;
动产;
房地产抵押;
资产重组;
OnPaint属性:TNotifyEvent read FOnPaint write FOnPaint;
结束;
程序登记册;
实施
程序登记册;
开始
注册表组件('aka',[TAframek]);
结束;
函数AframekStyleToInt(gs:TAframekStyle):LongInt;
开始
案件gs
gsBlackness:结果:=CMB粗糙度;
gsDstInvert:Result:=cmDstInvert;
gsMergeCopy:Result:=cmMergeCopy;
gsMergePaint:Result:=cmMergePaint;
gsNotSrcCopy:Result:=cmNotSrcCopy;
gsnotsrcrease:Result:=cmnotsrcrease;
gsPatCopy:Result:=cmPatCopy;
gsPatInvert:Result:=cmPatInvert;
gsPatPaint:结果:=cmPatPaint;
gsSrcAnd:Result:=cmSrcAnd;
gsSrcCopy:Result:=cmSrcCopy;
gssrcrease:Result:=cmsrcrease;
gsSrcInvert:Result:=cmSrcInvert;
gsSrcPaint:结果:=cmSrcPaint;
gsWhiteness:结果:=cmWhiteness;
else断言(True,“函数AframeStyleToInt中的错误参数”);
结束;
结束;
构造函数TAframek.Create(所有者:TComponent);
变量
FMarkBrush:LOGBRUSH;
FMarkPen:HPEN;
FPenStyle:整数的数组[0..1];
FStartAngle:单个;
开始
继承的创建(AOOwner);
缓冲区:=TBitmap.Create;
ControlStyle:=[CSAcceptsControl、csCaptureMouse、csClickEvents、,
csDoubleClicks,csreplicable];
宽度:=100;
高度:=100;
FStyle:=gsSrcAnd;
ParentCtl3d:=False;
Ctl3D:=假;
ParentColor:=假;
F颜色:=clWhite;
结束;
析构函数tak.Destroy;
开始
缓冲。免费;
继承性破坏;
结束;
程序tak.油漆;
变量
R:TRect;
rop:LongInt;
开始
R:=Rect(0,0,宽度,高度);
缓冲区宽度:=宽度;
缓冲区高度:=高度;
Buffer.Canvas.Brush.Style:=bsSolid;
Buffer.Canvas.Brush.Color:=FColor;
Buffer.Canvas.FillRect(Rect(0,0,宽度,高度));
rop:=AframekStyleToInt(FStyle);
StretchBlt(Buffer.Canvas.Handle、0、0、宽度、高度、,
画布。手柄,0,0,宽度,高度,rop);
如果是Ctl3D,则为draudge(Buffer.Canvas.Handle,R,BDR\u raisediner,BF\u RECT);
Buffer.Canvas.Pen.Mode:=pmCopy;
Buffer.Canvas.Pen.Style:=psSolid;
画布绘制(0,0,缓冲区);
如果指定(FOnPaint),则为FOnPaint(Self);
结束;
程序TAframek.SetColor(值:TColor);
开始
如果值为FColor,则
开始
F颜色:=值;
再创造;
结束;
结束;
过程TAframek.CreateParams(变量参数:TCreateParams);
开始
继承的CreateParams(Params);
Params.ExStyle:=Params.ExStyle+WS_EX_TRANSPARENT;
结束;
过程TAframek.WMWindowPosChanging(变量消息:TWMWindowPosChanging);
开始
使无效
继承;
结束;
过程TAframek.WMEraseBkgnd(变量消息:TMessage);
开始
消息。结果:=0;
结束;
程序TAframek.Resize;
开始
使无效
继承;
结束;
过程TAframek.CMCtl3DChanged(var消息:TMessage);
开始
继承;
再创造;
结束;
程序TAframek.SetStyle(值:TAframekStyle);
开始
如果