/// <include file='doc\ButtonRenderer.uex' path='docs/doc[@for="ButtonRenderer.IsBackgroundPartiallyTransparent"]/*' /> /// <devdoc> /// <para> /// Returns true if the background corresponding to the given state is partially transparent, else false. /// </para> /// </devdoc> public static bool IsBackgroundPartiallyTransparent(PushButtonState state) { if (RenderWithVisualStyles) { InitializeRenderer((int)state); return(visualStyleRenderer.IsBackgroundPartiallyTransparent()); } else { return(false); //for downlevel, this is false } }
protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e) { if (EnsureRenderer()) { // Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to // Rebar.Band.Normal) if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0))) { renderer.SetParameters(RebarClass, RebarBackground, 0); } else { renderer.SetParameters(RebarClass, 0, 0); } if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStripPanel.ClientRectangle, e.ToolStripPanel); } renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle); e.Handled = true; } else { base.OnRenderToolStripPanelBackground(e); } }
protected void UpdateRegion() { if (BackgroundRenderer == null) { return; } try { if (BackgroundRenderer.IsBackgroundPartiallyTransparent()) { using (var g = this.CreateGraphics()) this.Region = BackgroundRenderer.GetBackgroundRegion(g, ClientRectangle); } } catch { } }
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); } }
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()); }
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 = AppDefs.ColorQualityLow; Color clrEnd = AppDefs.ColorQualityHigh; 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); }
public void VisualStyleRenderer_IsBackgroundPartiallyTransparent_Invoke_ReturnsExpected() { var renderer = new VisualStyleRenderer("BUTTON", 0, 0); Assert.False(renderer.IsBackgroundPartiallyTransparent()); }
protected override void OnPaint(PaintEventArgs pevent) { base.OnPaint(pevent); if (pevent == null || !showSplit) { return; } Graphics g = pevent.Graphics; Rectangle bounds = this.ClientRectangle; // draw the button background as according to the current state. if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles) { Rectangle backgroundBounds = bounds; backgroundBounds.Inflate(-1, -1); ButtonRenderer.DrawButton(g, backgroundBounds, State); // button renderer doesnt draw the black frame when themes are off =( g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1); } else { if (renderer != null) { renderer.SetParameters(GetVisualStyleElement(State, Focused)); if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(g, bounds, this); } // // We are using the visual style of a window's close button. In order to render the 'X' offset from center, we render twice: // 1. Render the entire width of the control so the background of the dropdown arrow has the correct style // ------------- // | X | // ------------- // 2. Render the main button portion only which will cover up the originally centered 'X' and render the 'X' offset. // --------- // | X | // --------- // Rectangle boundsLessArrowPart = new Rectangle(bounds.Location, new Size(bounds.Width - PushButtonWidth, bounds.Height)); if (RightToLeft == System.Windows.Forms.RightToLeft.Yes) { boundsLessArrowPart.X += PushButtonWidth + 1; } renderer.DrawBackground(g, bounds); renderer.DrawBackground(g, boundsLessArrowPart); } else { ButtonRenderer.DrawButton(g, bounds, State); } } // calculate the current dropdown rectangle. dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth, bounds.Height - BorderSize * 2); int internalBorder = BorderSize; Rectangle focusRect = new Rectangle(internalBorder, internalBorder, bounds.Width - dropDownRectangle.Width - internalBorder, bounds.Height - (internalBorder * 2)); bool drawSplitLine = (State == PushButtonState.Hot || State == PushButtonState.Pressed || !Application.RenderWithVisualStyles); if (RightToLeft == RightToLeft.Yes) { dropDownRectangle.X = bounds.Left + 1; focusRect.X = dropDownRectangle.Right; if (drawSplitLine && renderer == null) { // draw two lines at the edge of the dropdown button g.DrawLine(SystemPens.ButtonShadow, bounds.Left + PushButtonWidth, BorderSize, bounds.Left + PushButtonWidth, bounds.Bottom - BorderSize); g.DrawLine(SystemPens.ButtonFace, bounds.Left + PushButtonWidth + 1, BorderSize, bounds.Left + PushButtonWidth + 1, bounds.Bottom - BorderSize); } } else { if (drawSplitLine && renderer == null) { // draw two lines at the edge of the dropdown button g.DrawLine(SystemPens.ButtonShadow, bounds.Right - PushButtonWidth, BorderSize, bounds.Right - PushButtonWidth, bounds.Bottom - BorderSize); g.DrawLine(SystemPens.ButtonFace, bounds.Right - PushButtonWidth - 1, BorderSize, bounds.Right - PushButtonWidth - 1, bounds.Bottom - BorderSize); } } // Draw an arrow in the correct location PaintArrow(g, dropDownRectangle, renderer == null ? SystemBrushes.ControlText : SystemBrushes.HighlightText); // Paint as normal if we don't have a renderer if (renderer == null) { // Figure out how to draw the text TextFormatFlags formatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter; // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand. if (!UseMnemonic) { formatFlags = formatFlags | TextFormatFlags.NoPrefix; } else if (!ShowKeyboardCues) { formatFlags = formatFlags | TextFormatFlags.HidePrefix; } if (!string.IsNullOrEmpty(this.Text)) { TextRenderer.DrawText(g, Text, Font, focusRect, SystemColors.ControlText, formatFlags); } // Draw the focus rectangle. if (State != PushButtonState.Pressed && Focused) { ControlPaint.DrawFocusRectangle(g, focusRect); } } }
protected override void OnPaint(PaintEventArgs args) { try { var tmpGraphics = args.Graphics; if (tmpGraphics == null) { base.OnPaint(args); return; } int normPosition = position - minimum, normMaximum = maximum - minimum; if (normMaximum <= 0) { normMaximum = 100; System.Diagnostics.Debug.Assert(false); } if (normPosition < 0) { normPosition = 0; System.Diagnostics.Debug.Assert(false); } if (normPosition > normMaximum) { normPosition = normMaximum; } Rectangle tmpDrawRectangle, tmpClientRectangle = this.ClientRectangle; var tmpStyleElement = VisualStyleElement.ProgressBar.Bar.Normal; if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(tmpStyleElement)) { var tmpStyleRenderer = new VisualStyleRenderer(tmpStyleElement); if (tmpStyleRenderer.IsBackgroundPartiallyTransparent( )) { tmpStyleRenderer.DrawParentBackground(tmpGraphics, tmpClientRectangle, this); } tmpStyleRenderer.DrawBackground(tmpGraphics, tmpClientRectangle); tmpDrawRectangle = tmpStyleRenderer.GetBackgroundContentRectangle(tmpGraphics, tmpClientRectangle); } else { tmpGraphics.FillRectangle(SystemBrushes.Control, tmpClientRectangle); var tempGrayPen = System.Drawing.SystemPens.ControlDark; var tmpWhitePen = System.Drawing.SystemPens.ControlLight; tmpGraphics.DrawLine(tempGrayPen, 0, 0, tmpClientRectangle.Width - 1, 0); tmpGraphics.DrawLine(tempGrayPen, 0, 0, 0, tmpClientRectangle.Height - 1); tmpGraphics.DrawLine(tmpWhitePen, tmpClientRectangle.Width - 1, 0, tmpClientRectangle.Width - 1, tmpClientRectangle.Height - 1); tmpGraphics.DrawLine(tmpWhitePen, 0, tmpClientRectangle.Height - 1, tmpClientRectangle.Width - 1, tmpClientRectangle.Height - 1); tmpDrawRectangle = new Rectangle(tmpClientRectangle.X + 1, tmpClientRectangle.Y + 1, tmpClientRectangle.Width - 2, tmpClientRectangle.Height - 2); } int tmpDrawWidth = (int)((float)tmpDrawRectangle.Width * normPosition / normMaximum); var tmpStartColor = this.qualityLowColor; var tmpEndOfColor = this.qualityHighColor; if (!this.Enabled) { tmpStartColor = HuiruiSoft.Utils.ColorUtils.ColorToGrayscale(SystemColors.ControlDark); tmpEndOfColor = HuiruiSoft.Utils.ColorUtils.ColorToGrayscale(SystemColors.ControlLight); } bool tmpRightToLeft = (this.RightToLeft == RightToLeft.Yes); if (tmpRightToLeft) { var tempColor = tmpStartColor; tmpStartColor = tmpEndOfColor; tmpEndOfColor = tempColor; } var tmpGradientBounds = new Rectangle(tmpDrawRectangle.X, tmpDrawRectangle.Y, tmpDrawRectangle.Width, tmpDrawRectangle.Height); if (!HuiruiSoft.Utils.WindowsUtils.IsAtLeastWindowsVista) { tmpGradientBounds.Inflate(1, 0); } using (var tmpFillBrush = new LinearGradientBrush(tmpGradientBounds, tmpStartColor, tmpEndOfColor, LinearGradientMode.Horizontal)) { tmpGraphics.FillRectangle(tmpFillBrush, tmpRightToLeft ? (tmpDrawRectangle.Width - tmpDrawWidth + 1) : tmpDrawRectangle.Left, tmpDrawRectangle.Top, tmpDrawWidth, tmpDrawRectangle.Height); } this.PaintText(tmpGraphics, tmpDrawRectangle, tmpRightToLeft); } catch (System.Exception) { System.Diagnostics.Debug.Assert(false); } }
protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e) { if (EnsureRenderer()) { // Don't render the panels containing status bars like they're // toolbars. You can move the status bar outside of the // container, so the TSM won't be forceful, but this is a bit // clumsy if you ask me. try { if (e.ToolStripPanel.Rows?[0]?.Controls?[0] is StatusStrip) { renderer.SetParameters(VisualStyleElement.Status.Bar.Normal); } else { // Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to // Rebar.Band.Normal) if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0))) { renderer.SetParameters(RebarClass, RebarBackground, 0); } else { renderer.SetParameters(RebarClass, 0, 0); } } } catch (ArgumentException) { // Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to // Rebar.Band.Normal) if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0))) { renderer.SetParameters(RebarClass, RebarBackground, 0); } else { renderer.SetParameters(RebarClass, 0, 0); } } if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStripPanel.ClientRectangle, e.ToolStripPanel); } renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle); // draw the edges if (RenderBorders) { // we don't handle the side toolbar cases, but they look weird anyways Edges edge = Edges.Top; foreach (var row in e.ToolStripPanel.Rows) { Rectangle edgeBounds = row.Bounds; // rendering the top edge for the menustrip ruins the // illusion of a seamlessness in Windows 10 if (edgeBounds.Y == 0) { continue; } edgeBounds.Offset(0, -1); renderer.DrawEdge(e.Graphics, edgeBounds, edge, EdgeStyle.Etched, EdgeEffects.None); } } e.Handled = true; } else { base.OnRenderToolStripPanelBackground(e); } }
public override bool IsBackgroundPartiallyTransparent() { return(_renderer.IsBackgroundPartiallyTransparent()); }