如题

解决方案 »

  1.   

    你把窗体上的Panel的颜色改为clBlack,然后你再把窗体的TransparentColor
    设为True,然后再把TransparentColorValue改为clBlack,运行试试是不是这
    个意思。
      

  2.   

    说什么?具体点:是隐藏还是xp风格的窗体,隐藏的话可以调用windows API函数, xp风格就象楼上说的那样改变颜色,隐藏是可以在在状态栏,任务管理器全部隐藏.
      

  3.   

    给你一个!
    还有其他功能,自己看吧
    在自动调整大小时,有些问题
    ==============================================================================={
    David 修改的来自网络的控件。
    可以实现:自动调整panel里的控件的位置和大小,添加背景
    在自动调整大小时,有些问题,如果修改好,请给我一份
    [email protected]}
    unit AutoPnl;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls;type  TPlacement = record
        Left, Top, Width, Height: Integer;
      end;
      TFooClass = class(TControl); { needed to get at protected }{ font property }  PIntArray = ^TRectArray;
      TRectArray = array[0..4096] of TPlacement;  TAutoPanel = class(TCustomPanel)
      private
        { Private declarations }
        FWallpaper: TPicture;
        FTransparent: Boolean;
        procedure SetTransparent(value: Boolean);
        procedure WallpaperChanged(Sender: TObject);
        procedure SetWallpaper(Value: TPicture);
      protected
        { Protected declarations }
       pWidth :Integer;
       pHeight:Integer;
       FAutoChildPosLeft : Boolean;
       FAutoChildPosTop : Boolean;
       FAutoChildWidth : Boolean;
       FAutoChildHeight : Boolean;
       PCtrlsCoordArr:PIntArray;
       procedure Resize; override;
       procedure Paint; override;
      // procedure CreateParams(var Params: TCreateParams); override;
      // procedure SetParent(AParent: TWinControl); override;
       procedure DrawParentImage(Control: TControl; Dest: TCanvas);
      public
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure Loaded; override;
    //    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;  published
        property AutoChildPosLeft : Boolean read FAutoChildPosLeft write FAutoChildPosLeft default False;
        property AutoChildPosTop : Boolean read FAutoChildPosTop write FAutoChildPosTop default False;
        property AutoChildWidth : Boolean  read FAutoChildWidth write FAutoChildWidth default False;
        property AutoChildHeight : Boolean read FAutoChildHeight write FAutoChildHeight default False;    property Align;
        property Alignment;
        property BevelInner;
        property BevelOuter;
        property BevelWidth;
        property BorderWidth;
        property BorderStyle;
        property DragCursor;
        property DragMode;
        property Enabled;
        property Caption;
        property Color;
        property Ctl3D;
        property Font;
        property Locked;
        property ParentColor;
        property ParentCtl3D;
        property ParentFont;
        property ParentShowHint;
        property PopupMenu;
      //  property ParentShowHint default False;
        property ShowHint default true;
        property TabOrder;
        property TabStop;
        property Wallpaper: TPicture read FWallpaper write SetWallpaper;
        property Transparent: Boolean read FTransparent write SetTransparent default false;
        property Visible;    property OnClick;
        property OnDblClick;
        property OnDragDrop;
        property OnDragOver;
        property OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnResize;
        property OnStartDrag;{$IFDEF VER120} {Borland Delphi 4.0 }
        property Anchors;
        property AutoSize;
        property BiDiMode;
        property Constraints;
        property UseDockManager default True;
        property DockSite;
        property DragKind;
        property FullRepaint;
        property ParentBiDiMode;    property OnCanResize;
        property OnConstrainedResize;
        property OnDockDrop;
        property OnDockOver;
        property OnEndDock;
        property OnGetSiteInfo;
        property OnStartDock;
        property OnUnDock;
    {$ENDIF}    { Published declarations }
      end;procedure Register;implementation procedure TAutoPanel.DrawParentImage(Control: TControl; Dest: TCanvas);
    var
      SaveIndex: Integer;
      DC: HDC;
      Position: TPoint;
    begin
      with Control do
      begin
        if Parent = nil then
          Exit;
        DC := Dest.Handle;
        SaveIndex := SaveDC(DC);
        {$IFDEF DFS_COMPILER_2}
        GetViewportOrgEx(DC, @Position);
        {$ELSE}
        GetViewportOrgEx(DC, Position);
        {$ENDIF}
        SetViewportOrgEx(DC, Position.X - Left, Position.Y - Top, nil);
        IntersectClipRect(DC, 0, 0, Parent.ClientWidth, Parent.ClientHeight);
        Parent.Perform(WM_ERASEBKGND, DC, 0);
        Parent.Perform(WM_PAINT, DC, 0);
        RestoreDC(DC, SaveIndex);
      end;
    end;constructor TAutoPanel.Create(AOwner: TComponent);
    begin
     inherited;
     FAutoChildPosLeft := False;
     FAutoChildPosTop := False;
     FAutoChildWidth := False;
     FAutoChildHeight := False;
     Caption:='';
     pWidth := -1;
     pHeight := -1;
     PCtrlsCoordArr := nil;
     FWallpaper := TPicture.Create;
     FWallpaper.OnChange := WallpaperChanged;
     ParentShowHint := False;
     ShowHint := True;
    // inherited Align := alTop;
    end;
    destructor TAutoPanel.Destroy;
    begin
     FreeMem(PCtrlsCoordArr);
     FWallpaper.OnChange := nil;
     FWallpaper.Free;
     FWallpaper := nil;
     inherited;
    end;
      

  4.   

    procedure TAutoPanel.Loaded;
    var i:Integer;
    begin
      inherited Loaded;
      if (csDesigning in ComponentState) then Exit;  if (pWidth = -1) and (pHeight = -1) then begin
       GetMem(PCtrlsCoordArr, ControlCount * sizeof(TRect));
       for  i := 0 to ControlCount - 1 do begin
          PCtrlsCoordArr[i].Left := Controls[i].Left;
          PCtrlsCoordArr[i].Top := Controls[i].Top;
          PCtrlsCoordArr[i].Width := Controls[i].Width;
          PCtrlsCoordArr[i].Height := Controls[i].Height;
       end;
       pWidth := Width;
       pHeight := Height;
      end;
    end;procedure TAutoPanel.Resize;
    var
     I:Integer;
    // Ph:integer;
    begin
     inherited;
     {
     TFooClass(Controls[i]).Font.Size :=
    (NewFormWidth div OldFormWidth) *
    TFooClass(Controls[i]).Font.Size;
    }
     if (csDesigning in ComponentState) then Exit;
     try  if (AutoChildPosLeft = false) and (AutoChildWidth = false) and
          (AutoChildPosTop = false) and (AutoChildHeight = false) then Exit;  for  i := 0 to ControlCount - 1 do begin
        if(AutoChildPosLeft = true) then
         if (AutoChildWidth = true) then begin
          Controls[i].Left := MulDiv (PCtrlsCoordArr[i].Left,Width,pWidth);
          Controls[i].Width :=  MulDiv (PCtrlsCoordArr[i].Width,Width,pWidth);     end
         else
           Controls[i].Left := Round(
            PCtrlsCoordArr[i].Left * Width / pWidth  +
            ((PCtrlsCoordArr[i].Width) * Width / pWidth -
            (PCtrlsCoordArr[i].Width))/2
            );    if(AutoChildPosTop = true) then
         if (AutoChildHeight = true) then begin
          Controls[i].Top := MulDiv (PCtrlsCoordArr[i].Top,Height,pHeight);
          Controls[i].Height := MulDiv (PCtrlsCoordArr[i].Height,Height,pHeight);
          //TFooClass(Controls[i]).Font.Size:= Round((Height/pHeight)*TFooClass(Controls[i]).Font.Size);
         end
         else       Controls[i].Top := Round(
            PCtrlsCoordArr[i].Top * Height / pHeight +
            ((PCtrlsCoordArr[i].Height)  * Height / pHeight - (PCtrlsCoordArr[i].Height))/2 );  end;
     finally
     end;
    end;//=======
    procedure TAutoPanel.WallpaperChanged(Sender: TObject);
    begin
      Invalidate;
    end;procedure TAutoPanel.SetWallpaper(Value: TPicture);
    begin
      FWallpaper.Assign(Value);
    end;procedure TAutoPanel.Paint;
    var
      XCnt, YCnt, X, Y: Integer;
      BevelSize, SaveIndex: Integer;
      Rect: TRect;
      bitmap:tbitmap;
    begin
      inherited Paint;
      if (FWallpaper.Graphic = nil) and FTransparent then
       begin
       // if not (csDesigning in ComponentState) then
       //  exit;
         Bitmap := TBitmap.Create;
        try
          Bitmap.Height := ClientRect.Bottom;
          Bitmap.Width := ClientRect.Right;
          DrawParentImage(Self, Bitmap.Canvas);
          canvas.CopyRect(ClientRect, Bitmap.canvas, ClientRect);
        finally
          Bitmap.free;
         end;
       end
       else
       begin
       if (FWallpaper.Graphic <> nil) and (FWallpaper.Width > 0) and
          (FWallpaper.Height > 0) then
        begin
          Rect := ClientRect;
          BevelSize := BorderWidth;
          if BevelOuter <> bvNone then Inc(BevelSize, BevelWidth);
          if BevelInner <> bvNone then Inc(BevelSize, BevelWidth);
          InflateRect(Rect, -BevelSize, -BevelSize);
          SaveIndex := SaveDC(Canvas.Handle);
          try
            IntersectClipRect(Canvas.Handle, Rect.Left, Rect.Top,
                    Rect.Right -Rect.Left +1,
                    Rect.Bottom-Rect.Top  +1 );
              XCnt := (ClientWidth - 2 * BevelSize) div FWallpaper.Width;
              YCnt := (ClientHeight - 2 * BevelSize) div FWallpaper.Height;
              for X := 0 to XCnt do
                for Y := 0 to YCnt do
                  Canvas.Draw(Rect.Left + X * FWallpaper.Width,
                    Rect.Top + Y * FWallpaper.Height, FWallpaper.Graphic);
          finally
            RestoreDC(Canvas.Handle, SaveIndex);
          end;
        end;
        end;
    end;//=======//透明
    procedure TAutoPanel.SetTransparent(value: boolean);
    begin
      if ftransparent <> value then
      begin
        ftransparent := value;
        invalidate;
      end;
    end;{procedure TAutoPanel.WMEraseBkgnd(var Msg: TMessage);
    begin
      if ftransparent then msg.result := 1
      else inherited;
    end;procedure TAutoPanel.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
    end;procedure TAutoPanel.SetParent(AParent: TWinControl);
    begin
      inherited setparent(aparent);
      if (aparent <> nil) and aparent.HandleAllocated
        and (GetWindowLong(aparent.handle, GWL_STYLE) and WS_CLIPCHILDREN <> 0) then
      setwindowlong(aparent.handle, GWL_STYLE,
                              GetWindowLong(aparent.handle, GWL_STYLE)
                              and not WS_CLIPCHILDREN);
    end;procedure TAutoPanel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
    begin
      invalidate;
      inherited setbounds(aleft, atop, awidth, aheight);
    end;}////procedure Register;
    begin
      RegisterComponents('Xac', [TAutoPanel]);
    end;end.
      

  5.   

    有个现成的控件:TCHPanel,可以设置透明属性。
      

  6.   

    TCHPanel控件不能用呀,设置之后,还是会挡在别的控件前面。