Region ManagedWindowGetWindowRegion (Form form) { if (form.WindowManager is MdiWindowManager && form.WindowManager.IsMaximized) return null; VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (form.WindowManager); if (!VisualStyleRenderer.IsElementDefined (title_bar_element)) return null; VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element); if (!renderer.IsBackgroundPartiallyTransparent ()) return null; IDeviceContext dc = GetMeasurementDeviceContext (); Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (form.WindowManager); Region region = renderer.GetBackgroundRegion (dc, title_bar_rectangle); ReleaseMeasurementDeviceContext (dc); region.Union (new Rectangle (0, title_bar_rectangle.Bottom, form.Width, form.Height)); return region; }
public static bool IsBackgroundPartiallyTransparent (GroupBoxState state) { if (!VisualStyleRenderer.IsSupported) return false; VisualStyleRenderer vsr; switch (state) { case GroupBoxState.Normal: default: vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal); break; case GroupBoxState.Disabled: vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled); break; } return vsr.IsBackgroundPartiallyTransparent (); }
public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds) { if (!RenderClientAreas || !cell.DataGridView.EnableHeadersVisualStyles || cell is DataGridViewTopLeftHeaderCell) return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds); VisualStyleElement element = DataGridViewColumnHeaderCellGetVisualStyleElement (cell); if (!VisualStyleRenderer.IsElementDefined (element)) return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds); bounds.Height--; VisualStyleRenderer renderer = new VisualStyleRenderer (element); if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ()) new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (g, bounds); renderer.DrawBackground (g, bounds); return true; }
public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds) { if (!RenderClientAreas || !cell.DataGridView.EnableHeadersVisualStyles) return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds); VisualStyleElement element = DataGridViewRowHeaderCellGetVisualStyleElement (cell); if (!VisualStyleRenderer.IsElementDefined (element)) return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds); bounds.Width--; Bitmap bitmap = new Bitmap (bounds.Height, bounds.Width); Graphics bitmap_g = Graphics.FromImage (bitmap); Rectangle bitmap_rectangle = new Rectangle (Point.Empty, bitmap.Size); VisualStyleRenderer renderer = new VisualStyleRenderer (element); if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ()) new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (bitmap_g, bitmap_rectangle); renderer.DrawBackground (bitmap_g, bitmap_rectangle); bitmap_g.Dispose (); g.Transform = new Matrix(0, 1, 1, 0, 0, 0); g.DrawImage (bitmap, bounds.Y, bounds.X); bitmap.Dispose (); g.ResetTransform (); return true; }
private void PaintNonClientRegion(ref Message m) { IntPtr handle = Handle; NativeMethods.RECT windowRect; NativeMethods.GetWindowRect(handle, out windowRect); windowRect = new NativeMethods.RECT( 0, 0, windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top); using (var deviceContext = new NativeMethods.DeviceContext(handle)) { var renderer = new VisualStyleRenderer( Enabled ? ReadOnly ? VisualStyleElement.TextBox.TextEdit.ReadOnly : VisualStyleElement.TextBox.TextEdit.Normal : VisualStyleElement.TextBox.TextEdit.Disabled); int clipResult = NativeMethods.ExcludeClipRect( deviceContext.GetHdc(), _borderRect.Left, _borderRect.Top, windowRect.Right - _borderRect.Right, windowRect.Bottom - _borderRect.Bottom); if (clipResult == NativeMethods.SIMPLEREGION || clipResult == NativeMethods.COMPLEXREGION) { if (renderer.IsBackgroundPartiallyTransparent()) renderer.DrawParentBackground(deviceContext, windowRect.ToRectangle(), this); renderer.DrawBackground(deviceContext, windowRect.ToRectangle()); } } m.Result = IntPtr.Zero; }
private void PaintPriv(PaintEventArgs e) { Graphics g = e.Graphics; if(g == null) { base.OnPaint(e); return; } int nNormPos = m_nPosition - m_nMinimum; int nNormMax = m_nMaximum - m_nMinimum; if(nNormMax <= 0) { Debug.Assert(false); nNormMax = 100; } if(nNormPos < 0) { Debug.Assert(false); nNormPos = 0; } if(nNormPos > nNormMax) { Debug.Assert(false); nNormPos = nNormMax; } Rectangle rectClient = this.ClientRectangle; Rectangle rectDraw; VisualStyleElement vse = VisualStyleElement.ProgressBar.Bar.Normal; if(VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(vse)) { VisualStyleRenderer vsr = new VisualStyleRenderer(vse); if(vsr.IsBackgroundPartiallyTransparent()) vsr.DrawParentBackground(g, rectClient, this); vsr.DrawBackground(g, rectClient); rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient); } else { g.FillRectangle(SystemBrushes.Control, rectClient); Pen penGray = SystemPens.ControlDark; Pen penWhite = SystemPens.ControlLight; g.DrawLine(penGray, 0, 0, rectClient.Width - 1, 0); g.DrawLine(penGray, 0, 0, 0, rectClient.Height - 1); g.DrawLine(penWhite, rectClient.Width - 1, 0, rectClient.Width - 1, rectClient.Height - 1); g.DrawLine(penWhite, 0, rectClient.Height - 1, rectClient.Width - 1, rectClient.Height - 1); rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1, rectClient.Width - 2, rectClient.Height - 2); } int nDrawWidth = (int)((float)rectDraw.Width * (float)nNormPos / (float)nNormMax); Color clrStart = Color.FromArgb(255, 128, 0); Color clrEnd = Color.FromArgb(0, 255, 0); if(!this.Enabled) { clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark); clrEnd = UIUtil.ColorToGrayscale(SystemColors.ControlLight); } bool bRtl = (this.RightToLeft == RightToLeft.Yes); if(bRtl) { Color clrTemp = clrStart; clrStart = clrEnd; clrEnd = clrTemp; } // Workaround for Windows <= XP Rectangle rectGrad = new Rectangle(rectDraw.X, rectDraw.Y, rectDraw.Width, rectDraw.Height); if(!WinUtil.IsAtLeastWindowsVista && !NativeLib.IsUnix()) rectGrad.Inflate(1, 0); using(LinearGradientBrush brush = new LinearGradientBrush(rectGrad, clrStart, clrEnd, LinearGradientMode.Horizontal)) { g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) : rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height); } PaintText(g, rectDraw); }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { if (e.ToolStrip.IsDropDown && IsSupported) { var renderer = new VisualStyleRenderer("menu", 9, 0); if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.ToolStrip); } renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds); } else { base.OnRenderToolStripBackground(e); } }