Redrawing Client Area with transparency
I need to render only the Client Area of a Control (TextBox) on winforms with transparency using GDI, because GDI+ doesn't support transparency for dynamic controls. I've already searched a lot, for two days, and founded two links:
I think if i join these two solutions, i can obtain what i want, but i don't know how to put them in code. Someone could help me please?
I tried use AlphaBlend, but is not working, here is my code:
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/25916.html
上一篇: 在Win32应用程序中托管的模态WPF对话框不会收到键盘事件
下一篇: 用透明度重绘客户区