我动态生成了一些对象放在一个容器里面,由于比较多,所以需要滚动条,就选择了ScrollBox,但是这个东东不透明,现在需要让它透明因为要露出ScrollBox下面Form上的一些图片。
应该怎么处理?哪里有透明的ScrollBox?或者可以用其它的什么方法来达到这个效果?
谢谢!

解决方案 »

  1.   

    可以使用scrollbar控件和panel控件配合
      

  2.   

    修改一下Delphi VCL的源代码就行了。,建立一个  ScrollBox1: TScrollBox; 
    按下Ctrl 单击TScrollBox 定位到以下单元的
    你在 Froms单元 中找一下
    {
      TScrollBox = class(TScrollingWinControl)
      private
        FBorderStyle: TBorderStyle;
        procedure SetBorderStyle(Value: TBorderStyle);
        procedure WMNCHitTest(var Message: TMessage); message WM_NCHITTEST;
        procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
      protected
        procedure CreateParams(var Params: TCreateParams); override;//找到这里
    }
    //在这里添加  找到这里
    procedure TScrollBox.CreateParams(var Params: TCreateParams);
    const
      BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
    begin
      inherited CreateParams(Params);
      with Params do
      begin
        Style := Style or BorderStyles[FBorderStyle];
        if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
        begin
          Style := Style and not WS_BORDER;
          ExStyle := ExStyle or WS_EX_CLIENTEDGE;
    //  { 增加透明 }//加上这句 就行了 ////////!!!!!!!!
          ExStyle := ExStyle or WS_EX_TRANSPARENT;
        end;  end;
    end;
      

  3.   

    樓上你的代碼測試通過了嘛?我這裡沒效果.
    自己寫個組件:unit TranScrollBox;interfaceuses
      SysUtils, Classes, Controls, Forms, Messages, Windows;type
      TTranScrollBox = class(TScrollBox)
      private
        { Private declarations }
        FTransparent: Boolean;
        procedure SetTransparent(value: Boolean);
        procedure WMEraseBkgnd(var Msg: TMessage); message WM_ERASEBKGND;
      protected
        procedure CreateParams(var Params: TCreateParams); override;
        procedure SetParent(AParent: TWinControl); override;
      public
        procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
      published
        property Transparent: Boolean read FTransparent write SetTransparent;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TTranScrollBox]);
    end;{ TTranScrollBox }procedure TTranScrollBox.CreateParams(var Params: TCreateParams);
    begin  inherited CreateParams(Params);
      params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
    end;procedure TTranScrollBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
    begin
      invalidate;
      inherited setbounds(aleft, atop, awidth, aheight);
    end;procedure TTranScrollBox.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 TTranScrollBox.SetTransparent(value: Boolean);
    begin
      if ftransparent <> value then
      begin
        ftransparent := value;
        invalidate;
      end;
    end;procedure TTranScrollBox.WMEraseBkgnd(var Msg: TMessage);
    begin
      if ftransparent then msg.result := 1
      else inherited;
    end;end.
      

  4.   

    我测试了通过了,XP + Delphi7在源代码中添加这一句就行了。
          ExStyle := ExStyle or WS_EX_TRANSPARENT;
    你是在VCL 的源代码中添加的吗?