需要用Panel遮住其后面的控件,不能点击,但是Panel又不想让看见,希望能透明,请高手指点指点。

解决方案 »

  1.   

    那直接设置窗体的Enabled属性不就可以了?
      

  2.   

    遮住?把panel放在底层就可以了,方法:选择panel,右键-选择置于底层
      

  3.   

    很多控件有Opacity属性,这个表示透明度的,0表示完全透明,1表示完全不透明,Panel有这个属性,你可以自己试着调整属性的值。
      

  4.   

    BackColor设置为 
    TransParent
      

  5.   

    窗体的Enabled不行,比如说我放了个webBrowser,目的是让WB里面加载的时候,不能点击其中内含的链接之类的东西,而且还得继续加载。Panel没有Opacity属性,BackColor的TransParent是和父窗体的颜色一致,但是,并不是透明的。还有更好的解决方案么?谢谢高手指点。
      

  6.   

    另外给一个曲线救国的效果很好的方法,抓图,吧当前窗体抓图,然后赋值给Panel作为背景,吧Panel添加到窗体,并设置z-order为顶层,dock = fill即可。private void button2_Click(object sender, EventArgs e)
    {
        Panel p = new Panel();
        p.Dock = DockStyle.Fill;
        Control frm = this;
        p.BackgroundImage = CaptureImage(ref frm);
        this.Controls.Add(p);
        p.BringToFront();
    }
    public Bitmap CaptureImage(ref Control c)
    {
        int hDC;
        int sh;
        int sw;
        if (c == null)
        {
            hDC = GetDC(0);
            sw = Screen.PrimaryScreen.Bounds.Width;
            sh = Screen.PrimaryScreen.Bounds.Height;
        }
        else
        {
            hDC = GetDC((int)c.Handle);
            sw = c.Width;
            sh = c.Height;
        }
        int hMDC = CreateCompatibleDC(hDC);
        int hBMP = CreateCompatibleBitmap(hDC, sw, sh);
        int hBMPOld = SelectObject(hMDC, hBMP);
        BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, 0xcc0020);
        hBMP = SelectObject(hMDC, hBMPOld);
        Bitmap result = Image.FromHbitmap(new IntPtr(hBMP));
        DeleteDC(hDC);
        DeleteDC(hMDC);
        DeleteObject(hBMP);
        return result;
    }
    [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleBitmap")]
    public static extern int CreateCompatibleBitmap(int hdc, int nWidth, int nHeight);
    [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]
    public static extern int CreateCompatibleDC(int hdc);
    [DllImport("user32.dll", EntryPoint = "GetDC")]
    public static extern int GetDC(int hwnd);
    [DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
    public static extern int DeleteDC(int hdc);
    [DllImport("gdi32.dll", EntryPoint = "SelectObject")]
    public static extern int SelectObject(int hdc, int hObject);
    [DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
    public static extern int DeleteObject(int hObject);
    [DllImport("gdi32.dll", EntryPoint = "BitBlt")]
    public static extern int BitBlt(int hDestDC, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc, int ySrc, int dwRop);
      

  7.   

    CaptureImage参数是控件,你可以吧参数用成你的webbrower,然后位置设置的和你的webbrower一样。就可以实现你的效果了。应该满足你要求了吧。
      

  8.   

    另外,如果你想实现完全的透明,类似网页上添加一个div层的效果。似乎是不可行的
      

  9.   

    找到了一个不错的透明控件,用于我上述的功能,如果能用到,就拿去吧,我也是转别人的,请勿商用。
    public partial class tspControl : UserControl
        {
            public tspControl()
            {
                InitializeComponent();
                SetStyle(ControlStyles.SupportsTransparentBackColor
                  | ControlStyles.UserPaint
                  | ControlStyles.AllPaintingInWmPaint
                  | ControlStyles.Opaque, true);
                this.BackColor = Color.Transparent;
            }        private Image img;
            public Image Image
            {
                get
                {
                    return img;
                }
                set
                {
                    img = value;
                }
            }        protected override void OnLocationChanged(EventArgs e)
            {
                //base.OnLocationChanged(e);
                Visible = false;
                Visible = true;
            }        protected override CreateParams CreateParams
            {
                get
                {
                    //return base.CreateParams;
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT 
                    return cp;
                }
            }
            protected override void OnPaint(PaintEventArgs pe)
            {
                if (img != null)
                {
                    base.OnPaint(pe);
                    pe.Graphics.DrawImage(img, 0, 0);
                }
                else
                {            }
            }
        }