用透明度重绘客户区

因为GDI +不支持动态控件的透明度,所以我只需要使用GDI以透明度渲染Winforms上的控件(TextBox)的客户区。 我已经搜索了很多,两天,并建立了两个链接:

  • https://msdn.microsoft.com/en-us/library/windows/desktop/dd162910(v=vs.85).aspx
  • http://www.winprog.org/tutorial/transparency.html
  • 我想如果我加入这两个解决方案,我可以获得我想要的,但我不知道如何将它们放入代码中。 有人可以帮助我吗?

    我试过使用AlphaBlend,但不工作,这里是我的代码:

    protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case PranchetaApp.Prancheta.Utils.GDIWrapper.WM_PAINT:
    
                    Bitmap memBmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, PixelFormat.Format32bppArgb);
    
                    IntPtr memdc = PranchetaApp.Prancheta.Utils.GDIWrapper.CreateCompatibleDC(this.CreateGraphics().GetHdc());
                    PranchetaApp.Prancheta.Utils.GDIWrapper.SelectObject(memdc, memBmp.GetHbitmap());
    
                    Graphics memDC = Graphics.FromHdc(memdc);
                    Graphics clientDC = this.CreateGraphics();
                    memDC.FillRectangle(new SolidBrush(Color.Blue), 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
    
                    IntPtr hdc = clientDC.GetHdc();
                    IntPtr hMemdc = memDC.GetHdc();
                    //PranchetaApp.Prancheta.Utils.GDIWrapper.BitBlt(hdc, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, hMemdc, 0, 0, PranchetaApp.Prancheta.Utils.GDIWrapper.SRCCOPY);
    
                    PranchetaApp.Prancheta.Utils.GDIWrapper.BLENDFUNCTION bfn;
                    bfn.AlphaFormat = 0;
                    bfn.BlendFlags = 0;
                    bfn.BlendOp = 0;
                    bfn.SourceConstantAlpha = 0;
    
                    PranchetaApp.Prancheta.Utils.GDIWrapper.AlphaBlend(hdc, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, hMemdc, 0, 0, this.ClientRectangle.Height, this.ClientRectangle.Height, bfn);
    
                    clientDC.ReleaseHdc(hdc);
                    memDC.ReleaseHdc(hMemdc);
    
                    break;
    
                default:
                    base.WndProc(ref m);
                    break;
    
            }
        }
    
    链接地址: http://www.djcxy.com/p/25915.html

    上一篇: Redrawing Client Area with transparency

    下一篇: Why is my window transparent when using AllowsTransparency="True"