我需要使用GDI在winforms上仅渲染控件(TextBox)的客户区域,因为GDI +不支持动态控件的透明度。我已经搜索了很多,已经两天了,并建立了两个链接:
我想如果我加入这两个解决方案,我可以获得我想要的东西,但我不知道如何将它们放入代码中。有人可以帮我吗?
我尝试过使用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;
}
}