private void DrawCashedCaptionBitmap() { if (m_CashedCaptionBitmap == null) return; try { IntPtr dc = WinApi.GetWindowDC(this.Handle); try { using (Graphics g = Graphics.FromHdc(dc)) { m_CashedCaptionBitmap.Render(g, m_CashedCaptionRegion); } } finally { WinApi.ReleaseDC(this.Handle, dc); } } finally { m_CashedCaptionBitmap.Dispose(); m_CashedCaptionBitmap = null; m_CashedCaptionRegion = null; } if (System.Environment.OSVersion.Version.Major >= 6) { this.RedrawBorder(); } else { if (m_RibbonControl != null) { foreach (Control c in m_RibbonControl.RibbonStrip.Controls) { if (c.Visible) { c.Refresh(); } } } } }
private void RecordStartState(object sender, EventArgs e) { m_StateBitmap = new Bitmap(m_ViewRectangle.Width, m_ViewRectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Graphics g1 = Graphics.FromImage(m_StateBitmap); BufferedBitmap bb = new BufferedBitmap(g1, new Rectangle(0, 0, m_ViewRectangle.Width, m_ViewRectangle.Height)); Graphics g = bb.Graphics; Color transparentColor = Color.Empty; try { bool disposeStyle = false; ElementStyle style = ElementStyleDisplay.GetElementStyle(this.BackgroundStyle, out disposeStyle); if (!style.BackColor.IsEmpty) transparentColor = style.BackColor; else if (style.BackColorBlend.Count > 0 && !style.BackColorBlend[0].Color.IsEmpty) transparentColor = style.BackColorBlend[0].Color; else transparentColor = Color.WhiteSmoke; if (!transparentColor.IsEmpty) { using (SolidBrush brush = new SolidBrush(transparentColor)) g.FillRectangle(brush, 0, 0, m_StateBitmap.Width, m_StateBitmap.Height); } System.Windows.Forms.Control cc = this.ContainerControl as System.Windows.Forms.Control; bool antiAlias = false; ItemPaintArgs pa = null; if (cc is ItemControl) { antiAlias = ((ItemControl)cc).AntiAlias; pa = ((ItemControl)cc).GetItemPaintArgs(g); } else if (cc is Bar) { antiAlias = ((Bar)cc).AntiAlias; pa = ((Bar)cc).GetItemPaintArgs(g); } else if (cc is ButtonX) { antiAlias = ((ButtonX)cc).AntiAlias; pa = ((ButtonX)cc).GetItemPaintArgs(g); } else if (cc is MenuPanel) { antiAlias = ((MenuPanel)cc).AntiAlias; pa = ((MenuPanel)cc).GetItemPaintArgs(g); } Rectangle clip = GetClipRectangle(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); myMatrix.Translate( -(clip.X + +m_ScrollPosition.X), -(clip.Y + m_ScrollPosition.Y), System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; if (antiAlias) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint; } if (pa == null) { m_StateBitmap.Dispose(); m_StateBitmap = null; } // Do not paint scrollbars just content ItemDisplay display = GetItemDisplay(); display.Paint(this, pa); bb.Render(g1); if(disposeStyle) style.Dispose(); } finally { g = null; bb.Dispose(); g1.Dispose(); } if (!transparentColor.IsEmpty) m_StateBitmap.MakeTransparent(transparentColor); }
private void CreateCashedCaptionBitmap() { if (m_RibbonControl == null || this.WindowState == FormWindowState.Minimized || !this.IsHandleCreated || !m_RibbonControl.IsHandleCreated || m_RibbonControl.RibbonStrip == null || m_RibbonControl.RibbonStrip.Width <= 0 || m_RibbonControl.RibbonStrip.Height <= 0 || !m_RibbonControl.Visible) return; if (m_CashedCaptionBitmap != null) { m_CashedCaptionBitmap.Dispose(); m_CashedCaptionBitmap = null; } if (m_CashedCaptionRegion != null) { m_CashedCaptionRegion = null; } Rectangle r = m_RibbonControl.RibbonStrip.Bounds; r.Location = m_RibbonControl.PointToScreen(r.Location); r.Location = this.PointToClient(r.Location); NonClientInfo nci = GetNonClientInfo(); if (this.IsGlassEnabled) r.X += nci.LeftBorder /* * NativeFunctions.BorderMultiplierFactor*/; m_CashedCaptionBitmapLocation = r.Location; if (this.WindowState == FormWindowState.Maximized) m_CashedCaptionBitmapLocation.Offset(m_NonClientOffset.X, m_NonClientOffset.Y); ArrayList clips = new ArrayList(10); Size bmpSize = new Size(m_RibbonControl.RibbonStrip.Width, Math.Min(m_RibbonControl.RibbonStrip.Height, m_RibbonControl.Height)); IntPtr hdc = WinApi.GetWindowDC(this.Handle); m_CashedCaptionBitmap = new BufferedBitmap(hdc, new Rectangle(m_CashedCaptionBitmapLocation, bmpSize)); WinApi.ReleaseDC(this.Handle, hdc); using (PaintEventArgs paintEventArgs = new PaintEventArgs(m_CashedCaptionBitmap.Graphics, Rectangle.Empty)) m_RibbonControl.RibbonStrip.InternalPaint(paintEventArgs); foreach (Control c in m_RibbonControl.RibbonStrip.Controls) { if (c.Visible) { Rectangle rc = c.Bounds; rc.Location = m_RibbonControl.RibbonStrip.PointToScreen(rc.Location); rc.Location = this.PointToClient(rc.Location); clips.Add(rc); } } m_CashedCaptionRegion = new Rectangle[clips.Count]; clips.CopyTo(m_CashedCaptionRegion); }
//protected override void OnPaintBackground(PaintEventArgs e) //{ // base.OnPaintBackground(e); // Graphics g = e.Graphics; // Rectangle r = new Rectangle(0,0,this.Width-1, this.Height-1); // using (GraphicsPath path = GetFormPath(r)) // { // using (Pen pen = new Pen(Color.Red, 1)) // { // path.Widen(pen); // SmoothingMode sm = g.SmoothingMode; // g.SmoothingMode = SmoothingMode.HighQuality; // g.DrawPath(pen, path); // //g.FillPath(SystemBrushes.ControlDarkDark, path); // g.SmoothingMode = sm; // } // } //} #region Non-client area painting /// <summary> /// Paints the non-client area of the form. /// </summary> protected virtual bool WindowsMessageNCPaint(ref Message m) { if (this.IsGlassEnabled) { return true; } else { if (BarFunctions.IsVista && !BarFunctions.IsWindows7 && _NonClientPaintEnabled) { IntPtr dc = WinApi.GetWindowDC(this.Handle); try { using (Graphics g = Graphics.FromHdc(dc)) { BufferedBitmap bmp = new BufferedBitmap(g, new Rectangle(0, 0, this.Width, this.Height)); try { bmp.Graphics.SetClip(this.GetClientRectangle(new Rectangle(0, 0, this.Width, this.Height)), CombineMode.Exclude); PaintFormBorder(new PaintEventArgs(bmp.Graphics, Rectangle.Empty)); bmp.Render(g, this.GetClientRectangle(new Rectangle(0, 0, this.Width, this.Height))); } finally { bmp.Dispose(); } } } finally { WinApi.ReleaseDC(this.Handle, dc); } } m.Result = IntPtr.Zero; return false; } }
private void DrawCashedCaptionBitmap() { if (m_CashedCaptionBitmap == null) return; IntPtr dc = WinApi.GetWindowDC(this.Handle); using (Graphics g = Graphics.FromHdc(dc)) { m_CashedCaptionBitmap.Render(g); } WinApi.ReleaseDC(this.Handle, dc); m_CashedCaptionBitmap.Dispose(); m_CashedCaptionBitmap = null; }
private void CreateCashedCaptionBitmap() { if (m_CashedCaptionBitmap != null) { m_CashedCaptionBitmap.Dispose(); m_CashedCaptionBitmap = null; } if (m_Caption.DisplayRectangle.Width <= 0 || m_Caption.DisplayRectangle.Height <= 0 || !this.IsHandleCreated || this.IsDisposed) return; IntPtr dc = WinApi.GetWindowDC(this.Handle); try { m_CashedCaptionBitmap = new BufferedBitmap(dc, new Rectangle(m_CashedCaptionBitmapLocation.X, m_CashedCaptionBitmapLocation.Y, m_Caption.DisplayRectangle.Width, m_Caption.DisplayRectangle.Height)); } finally { WinApi.ReleaseDC(this.Handle, dc); } PaintFormCaptionTo(m_CashedCaptionBitmap.Graphics); }
protected virtual void PaintNonClientAreaBuffered(Graphics targetGraphics) { BufferedBitmap bmp = new BufferedBitmap(targetGraphics, new Rectangle(0,0,this.Width, this.Height)); try { bmp.Graphics.SetClip(this.GetClientRectangle(new Rectangle(0, 0, this.Width, this.Height)), CombineMode.Exclude); PaintNonClientArea(bmp.Graphics); bmp.Render(targetGraphics, this.GetClientRectangle(new Rectangle(0, 0, this.Width, this.Height))); } finally { bmp.Dispose(); } }