/// <summary> /// Renders a horizontal tick. /// </summary> public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) { if (numTicks <= 0 || bounds.Height <= 0 || bounds.Width <= 0 || g == null) { return; } InitializeRenderer(VisualStyleElement.TrackBar.Ticks.Normal, 1); //trivial case -- avoid calcs if (numTicks == 1) { visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None); return; } float inc = ((float)bounds.Width - lineWidth) / ((float)numTicks - 1); while (numTicks > 0) { //draw the nth tick float x = bounds.X + ((float)(numTicks - 1)) * inc; visualStyleRenderer.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None); numTicks--; } }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { if (EnsureRenderer()) { renderer.SetParameters(MenuClass, (int)MenuParts.PopupBorders, 0); if (e.ToolStrip.IsDropDown) { Region oldClip = e.Graphics.Clip; // Tool strip borders are rendered *after* the content, for some reason. // So we have to exclude the inside of the popup otherwise we'll draw over it. Rectangle insideRect = e.ToolStrip.ClientRectangle; insideRect.Inflate(-1, -1); e.Graphics.ExcludeClip(insideRect); renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds); // Restore the old clip in case the Graphics is used again (does that ever happen?) e.Graphics.Clip = oldClip; } else if (e.ToolStrip is MenuStrip) { renderer.DrawEdge(e.Graphics, e.ToolStrip.ClientRectangle, Edges.Bottom, EdgeStyle.Sunken, EdgeEffects.Flat); } } else { base.OnRenderToolStripBorder(e); } }
public void VisualStyleRenderer_DrawEdge_InvalidEffects_ThrowsInvalidEnumArgumentException(EdgeEffects effects) { var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var bitmap = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); Assert.Throws <InvalidEnumArgumentException>("effects", () => renderer.DrawEdge(graphics, new Rectangle(1, 2, 3, 4), Edges.Bottom, EdgeStyle.Bump, effects)); }
public void VisualStyleRenderer_DrawEdge_Invoke_Success(Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects) { // Don't verify anything, just make sure the interop call succeeds. var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var bitmap = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); Rectangle result = renderer.DrawEdge(graphics, bounds, edges, style, effects); Assert.Equal(0, renderer.LastHResult); }
public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) { if (((numTicks > 0) && (bounds.Height > 0)) && ((bounds.Width > 0) && (g != null))) { InitializeRenderer(VisualStyleElement.TrackBar.Ticks.Normal, 1); if (numTicks == 1) { visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, 2, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None); } else { float num = (bounds.Width - 2f) / (numTicks - 1f); while (numTicks > 0) { float num2 = bounds.X + ((numTicks - 1) * num); visualStyleRenderer.DrawEdge(g, new Rectangle((int)Math.Round((double)num2), bounds.Y, 2, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None); numTicks--; } } } }
private void SimpleStyleRenderer_Paint(object sender, PaintEventArgs e) { VisualStyleElement element = VisualStyleElement.Button.CheckBox.CheckedNormal; if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); Rectangle rectCheck = new Rectangle(10, 10, 50, 50); Rectangle rectBox = new Rectangle(10, 10, 200, 50); Rectangle rectText = new Rectangle(50, 25, 150, 25); renderer.DrawBackground(e.Graphics, rectCheck); renderer.DrawEdge(e.Graphics, rectBox, Edges.Bottom | Edges.Top | Edges.Left | Edges.Right, EdgeStyle.Etched, EdgeEffects.Flat); renderer.DrawText(e.Graphics, rectText, "Styled checkbox", false, TextFormatFlags.Top); } else { // (Perform ControlPaint drawing here.) } }
public static void DrawVerticalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) { if (!IsSupported) { throw new InvalidOperationException(); } if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0) { return; } VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.TrackBar.TicksVertical.Normal); double y = bounds.Top; double delta = (double)(bounds.Height - 2) / (double)(numTicks - 1); for (int i = 0; i < numTicks; i++) { vsr.DrawEdge(g, new Rectangle(bounds.Left, (int)Math.Round(y), bounds.Width, 5), Edges.Top, edgeStyle, EdgeEffects.None); y += delta; } }
private void panel1_Paint(object sender, PaintEventArgs e) { renderer.DrawEdge(e.Graphics, panel1.ClientRectangle, Edges.Bottom | Edges.Left | Edges.Right | Edges.Top, EdgeStyle.Raised, EdgeEffects.Flat); }
public void VisualStyleRenderer_DrawEdge_NullDc_ThrowsArgumentNullException() { var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); Assert.Throws <ArgumentNullException>("dc", () => renderer.DrawEdge(null, new Rectangle(1, 2, 3, 4), Edges.Top, EdgeStyle.Bump, EdgeEffects.FillInterior)); }
internal void DrawTab(Graphics g, TabPage tabPage, int nIndex) { Rectangle recBounds = this.GetTabRect(nIndex); RectangleF tabTextArea = (RectangleF)this.GetTabRect(nIndex); bool bSelected = (this.SelectedIndex == nIndex); bool bHot = false; VisualStyleRenderer render = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal); if (tabPage.Tag != null) { bHot = (bool)tabPage.Tag; } //Align? if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Offset(2, 0); recBounds.Width = recBounds.Width + 1; } else { //right or left recBounds.Offset(0, 1); recBounds.Height = recBounds.Height + 0; tabTextArea.Height = tabTextArea.Height - 2; tabTextArea.Offset(-2, 0); //and selected if (bSelected) { if (Alignment == TabAlignment.Left) { recBounds.Width = recBounds.Width + 3; tabTextArea.Width = tabTextArea.Width + 3; } else { recBounds.X = recBounds.X - 3; recBounds.Width = recBounds.Width + 3; tabTextArea.X = tabTextArea.X - 3; tabTextArea.Width = tabTextArea.Width + 3; } } } //Tab Selected if (bSelected) { //highter if selected and no multiline if (this.Multiline != true) { if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Height = recBounds.Height + 2; recBounds.Width = recBounds.Width - 1; } } else //lower profile { if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Y = recBounds.Y + 1; recBounds.Height = recBounds.Height + 1; recBounds.Width = recBounds.Width - 1; tabTextArea.Offset(0, 1); } } render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed); render.DrawBackground(g, recBounds); render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat); } //Tab HotTrack else if (bHot) { if (bSelected) //hot and selected Multiline { //highter if selected and no multiline if (this.Multiline != true) { if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Height = recBounds.Height + 2; recBounds.Width = recBounds.Width - 1; } } else//lower if selected and multiline { if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Y = recBounds.Y + 1; recBounds.Height = recBounds.Height + 1; recBounds.Width = recBounds.Width - 1; tabTextArea.Offset(0, 1); } } } //tab Hot and not selected else { if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { //smaller if not selected, text lower recBounds.Y = recBounds.Y + 3; recBounds.Height = recBounds.Height - 2; tabTextArea.Offset(0, 2); } } render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot); render.DrawBackground(g, recBounds); render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat); } //Tab Normal else { //smaller if not selected, text lower if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) { recBounds.Y = recBounds.Y + 3; recBounds.Height = recBounds.Height - 2; tabTextArea.Offset(0, 2); } render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal); render.DrawBackground(g, recBounds); render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat); } //DrawBottomLine if (Alignment != TabAlignment.Top) { render.DrawEdge(g, recBounds, Edges.Bottom, EdgeStyle.Sunken, EdgeEffects.Flat); } //image management if ((tabPage.ImageIndex >= 0) && ((ImageList != null)) && ((ImageList.Images[tabPage.ImageIndex] != null))) { int nLeftMargin = 8; int nRightMargin = 1; Image img = ImageList.Images[tabPage.ImageIndex]; Rectangle rimage = new Rectangle(recBounds.X + nLeftMargin, recBounds.Y + 1, img.Width, img.Height); float nAdj = (float)(nLeftMargin + img.Width + nRightMargin); // adjust rectangles for top, bottom and ExtendedLayout if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom || _useExtendedLayout == true) { nAdj = (float)(nLeftMargin + img.Width + nRightMargin); rimage.Y += (recBounds.Height - img.Height) / 2; tabTextArea.X += nAdj; tabTextArea.Width -= nAdj; //selected if (bSelected) { //normal if (!_useExtendedLayout) { rimage.Offset(0, -1); } //exted Layout else { rimage.Offset(2, 0); } } } else { //not ExtendedLayout, not rotate if left tab page if (_useExtendedLayout == false) { img.RotateFlip(RotateFlipType.Rotate90FlipNone); //rimage.X += (recBounds.Width - img.Width) / 2; rimage.X -= 4; rimage.Y += 3; nAdj = (float)(10 + img.Height); tabTextArea.Y += img.Height; tabTextArea.Height -= img.Height; } } g.DrawImage(img, rimage); } //string management StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; if (FlagControl) { stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; } else { stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide; } Brush br; if (!bHot) { br = new SolidBrush(tabPage.ForeColor); } else { if (_useKrypton) { br = new SolidBrush(_hotForeColour); } else { br = new SolidBrush(tabPage.ForeColor); } } //use AntiAlias if (Utility.IsVista()) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; } else { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; } //Vertical Orientation if ((this.Alignment == TabAlignment.Left) || (this.Alignment == TabAlignment.Right)) { //not ExtendedLayout if (_useExtendedLayout == false) { stringFormat.FormatFlags = StringFormatFlags.DirectionVertical; } else //Extended Layout { tabTextArea.Offset(1, 2); tabTextArea.Width = tabTextArea.Width - 2; stringFormat.FormatFlags = StringFormatFlags.NoWrap; stringFormat.Trimming = StringTrimming.EllipsisCharacter; } } g.DrawString(tabPage.Text, Font, br, tabTextArea, stringFormat); bHot = 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); } }