private void UpdateLayeredWindow() { Bitmap bitmap1 = new Bitmap(Size.Width, Size.Height, PixelFormat.Format32bppArgb); using (Graphics graphics1 = Graphics.FromImage(bitmap1)) { SizeStruct size1; PointStruct point1; PointStruct point2; Rectangle rectangle1 = new Rectangle(0, 0, Size.Width, Size.Height); PerformPaint(new PaintEventArgs(graphics1, rectangle1)); IntPtr ptr1 = User32.GetDC(IntPtr.Zero); IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1); IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0)); IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3); size1.cx = Size.Width; size1.cy = Size.Height; point1.x = Location.X; point1.y = Location.Y; point2.x = 0; point2.y = 0; Blendfunction blendfunction1 = new Blendfunction { BlendOp = 0, BlendFlags = 0, SourceConstantAlpha = _alpha, AlphaFormat = 1 }; User32.UpdateLayeredWindow(Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA Gdi32.SelectObject(ptr2, ptr4); User32.ReleaseDC(IntPtr.Zero, ptr1); Gdi32.DeleteObject(ptr3); Gdi32.DeleteDC(ptr2); } }
internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref PointStruct pptDst, ref SizeStruct psize, IntPtr hdcSrc, ref PointStruct pprSrc, int crKey, ref Blendfunction pblend, int dwFlags);