protected void DrawTransparentBackground( IntPtr hDC, Rectangle bounds, Point offset) { if (base.Parent == null || !base.Parent.IsHandleCreated || base.Parent.IsDisposed) { return; } Size parentSize = base.Parent.ClientSize; using (ImageDc imageDc = new ImageDc(parentSize.Width, parentSize.Height)) { Win32.NativeMethods.SendMessage( base.Parent.Handle, WM.WM_ERASEBKGND, imageDc.Hdc, 0); Win32.NativeMethods.SendMessage( base.Parent.Handle, WM.WM_PAINT, imageDc.Hdc, 0); Win32.NativeMethods.BitBlt( hDC, bounds.X, bounds.Y, bounds.Width, bounds.Height, imageDc.Hdc, offset.X, offset.Y, TernaryRasterOperations.SRCCOPY); } }
protected void DrawTransparentBackground( IntPtr hDC, Rectangle bounds, Point offset) { if(base.Parent == null || !base.Parent.IsHandleCreated || base.Parent .IsDisposed) { return; } Size parentSize = base.Parent.ClientSize; using (ImageDc imageDc = new ImageDc(parentSize.Width, parentSize.Height)) { Win32.NativeMethods.SendMessage( base.Parent.Handle, WM.WM_ERASEBKGND, imageDc.Hdc, 0); Win32.NativeMethods.SendMessage( base.Parent.Handle, WM.WM_PAINT, imageDc.Hdc, 0); Win32.NativeMethods.BitBlt( hDC, bounds.X, bounds.Y, bounds.Width, bounds.Height, imageDc.Hdc, offset.X, offset.Y, TernaryRasterOperations.SRCCOPY); } }
protected virtual void WmNcPaint(ref Message m) { IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd); if (hDC == IntPtr.Zero) { return; } try { Rectangle bounds = new Rectangle(Point.Empty, base.Size); Rectangle client = base.ClientRectangle; client.X = _borderWidth; client.Y = _borderWidth; using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height)) { Win32.NativeMethods.ExcludeClipRect( bufferedDC.Hdc, client.Left, client.Top, client.Right, client.Bottom); DrawTransparentBackground( bufferedDC.Hdc, bounds, base.Location); using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { g.SetClip(path); } g.ExcludeClip(client); if (base.BackgroundImage != null) { ControlPaintEx.DrawBackgroundImage( g, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } else if (base.BackColor != Color.Transparent) { using (Brush brush = new SolidBrush(base.BackColor)) { g.FillRectangle(brush, bounds); } } g.ResetClip(); using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { using ( SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g)) { g.DrawPath(Pens.Black, path); } } } Win32.NativeMethods.ExcludeClipRect( hDC, client.Left, client.Top, client.Right, client.Bottom); Win32.NativeMethods.BitBlt( hDC, bounds.X, bounds.Y, bounds.Width, bounds.Height, bufferedDC.Hdc, 0, 0, TernaryRasterOperations.SRCCOPY); } } catch { } finally { Win32.NativeMethods.ReleaseDC(m.HWnd, hDC); } }
protected override void OnPaintBackground(PaintEventArgs e) { if (base.BackgroundImage != null) { Graphics g = e.Graphics; Rectangle bounds = new Rectangle(Point.Empty,base.Size); Rectangle clientRect = base.ClientRectangle; WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); IntPtr hDC = g.GetHdc(); try { using (ImageDc imageDc = new ImageDc(bounds.Width, bounds.Height)) { using (Graphics gDc = Graphics.FromHdc(imageDc.Hdc)) { ControlPaintEx.DrawBackgroundImage( gDc, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } Win32.NativeMethods.BitBlt( hDC, clientRect.X, clientRect.Y, clientRect.Width, clientRect.Height, imageDc.Hdc, offset.X, offset.Y, TernaryRasterOperations.SRCCOPY); } } catch { } finally { g.ReleaseHdc(hDC); } return; } if (base.BackColor == Color.Transparent) { Graphics g = e.Graphics; IntPtr hDC = g.GetHdc(); try { WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); offset += (Size)base.Location; DrawTransparentBackground( hDC, base.ClientRectangle, offset); } catch { } finally { g.ReleaseHdc(hDC); } return; } base.OnPaintBackground(e); }
protected virtual void WmNcPaint(ref Message m) { IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd); if (hDC == IntPtr.Zero) { return; } try { Rectangle bounds = new Rectangle(Point.Empty, base.Size); Rectangle client = base.ClientRectangle; client.X = _borderWidth; client.Y = _borderWidth; using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height)) { Win32.NativeMethods.ExcludeClipRect( bufferedDC.Hdc, client.Left, client.Top, client.Right, client.Bottom); DrawTransparentBackground( bufferedDC.Hdc, bounds, base.Location); using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { g.SetClip(path); } g.ExcludeClip(client); if (base.BackgroundImage != null) { ControlPaintEx.DrawBackgroundImage( g, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } else if (base.BackColor != Color.Transparent) { using (Brush brush = new SolidBrush(base.BackColor)) { g.FillRectangle(brush, bounds); } } g.ResetClip(); using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { using (SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g)) { g.DrawPath(Pens.Black, path); } } } Win32.NativeMethods.ExcludeClipRect( hDC, client.Left, client.Top, client.Right, client.Bottom); Win32.NativeMethods.BitBlt( hDC, bounds.X, bounds.Y, bounds.Width, bounds.Height, bufferedDC.Hdc, 0, 0, TernaryRasterOperations.SRCCOPY); } } catch { } finally { Win32.NativeMethods.ReleaseDC(m.HWnd, hDC); } }
protected override void OnPaintBackground(PaintEventArgs e) { if (base.BackgroundImage != null) { Graphics g = e.Graphics; Rectangle bounds = new Rectangle(Point.Empty, base.Size); Rectangle clientRect = base.ClientRectangle; WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); IntPtr hDC = g.GetHdc(); try { using (ImageDc imageDc = new ImageDc(bounds.Width, bounds.Height)) { using (Graphics gDc = Graphics.FromHdc(imageDc.Hdc)) { ControlPaintEx.DrawBackgroundImage( gDc, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } Win32.NativeMethods.BitBlt( hDC, clientRect.X, clientRect.Y, clientRect.Width, clientRect.Height, imageDc.Hdc, offset.X, offset.Y, TernaryRasterOperations.SRCCOPY); } } catch { } finally { g.ReleaseHdc(hDC); } return; } if (base.BackColor == Color.Transparent) { Graphics g = e.Graphics; IntPtr hDC = g.GetHdc(); try { WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); offset += (Size)base.Location; DrawTransparentBackground( hDC, base.ClientRectangle, offset); } catch { } finally { g.ReleaseHdc(hDC); } return; } base.OnPaintBackground(e); }