internal static void DrawButtonForHandle( IDeviceContext deviceContext, Rectangle bounds, bool focused, PushButtonState state, IntPtr hwnd) { Rectangle contentBounds; Graphics g = deviceContext.TryGetGraphics(create: true); if (RenderWithVisualStyles) { InitializeRenderer((int)state); using var hdc = new DeviceContextHdcScope(deviceContext); t_visualStyleRenderer.DrawBackground(hdc, bounds, hwnd); contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(hdc, bounds); } else { Graphics graphics = deviceContext.TryGetGraphics(create: true); ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state)); contentBounds = Rectangle.Inflate(bounds, -3, -3); } if (focused) { Graphics graphics = deviceContext.TryGetGraphics(create: true); ControlPaint.DrawFocusRectangle(graphics, contentBounds); } }
private static void DrawBackground(Graphics g, Rectangle bounds, ComboBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); if ((state != ComboBoxState.Disabled) && (visualStyleRenderer.GetColor(ColorProperty.FillColor) != SystemColors.Window)) { Rectangle backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); backgroundContentRectangle.Inflate(-2, -2); g.FillRectangle(SystemBrushes.Window, backgroundContentRectangle); } }
private static void DrawBackground(Graphics g, Rectangle bounds, TextBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); if ((state != TextBoxState.Disabled) && (visualStyleRenderer.GetColor(ColorProperty.FillColor) != SystemColors.Window)) { Rectangle backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); using (SolidBrush brush = new SolidBrush(SystemColors.Window)) { g.FillRectangle(brush, backgroundContentRectangle); } } }
private static void DrawBackground(Graphics g, Rectangle bounds, TextBoxState state) { t_visualStyleRenderer.DrawBackground(g, bounds); if (state != TextBoxState.Disabled) { Color windowColor = t_visualStyleRenderer.GetColor(ColorProperty.FillColor); if (windowColor != SystemColors.Window) { Rectangle fillRect = t_visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); g.FillRectangle(SystemBrushes.Window, fillRect); } } }
private static void DrawBackground(Graphics g, Rectangle bounds, TextBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); if (state != TextBoxState.Disabled) { Color windowColor = visualStyleRenderer.GetColor(ColorProperty.FillColor); if (windowColor != SystemColors.Window) { Rectangle fillRect = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); //then we need to re-fill the background. using (SolidBrush brush = new SolidBrush(SystemColors.Window)) { g.FillRectangle(brush, fillRect); } } } }
protected void PaintTab(BpTabPage page, Graphics g) { Rectangle bounds = GetTabRect(page); VisualStyleElement element = GetElement(page); if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, bounds); bounds = renderer.GetBackgroundContentRectangle(g, bounds); } else { ControlPaint.DrawBorder3D(g, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Middle); } if (IncludesCloseButton(page)) { Rectangle closerect = GetTabCloseRect(page, bounds); element = VisualStyleElement.ToolTip.Close.Normal; Border3DStyle borderstyle = Border3DStyle.Flat; if (hoverClose) { if (clickClose == page) { element = VisualStyleElement.ToolTip.Close.Pressed; borderstyle = Border3DStyle.Sunken; } else if (clickClose == null) { element = VisualStyleElement.ToolTip.Close.Hot; borderstyle = Border3DStyle.Raised; } } if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, closerect); } else { if (borderstyle != Border3DStyle.Flat) { ControlPaint.DrawBorder3D(g, closerect, borderstyle); } Font closefont = new Font("Marlett", SystemFonts.MenuFont.Size); Point pos = closerect.Location; pos.X += SystemInformation.Border3DSize.Width; pos.Y += SystemInformation.Border3DSize.Height; TextRenderer.DrawText(g, "r", closefont, pos, Color.Black); } } bounds = GetTabContentRect(page, bounds); TabPaintEventArgs ea = new TabPaintEventArgs(g, bounds, page); OnTabPaint(ea); page.CallTabPaint(ea); }
private static void DrawBackground(Graphics g, Rectangle bounds, ComboBoxState state) { visualStyleRenderer.DrawBackground(g, bounds); //for disabled comboboxes, comctl does not use the window backcolor, so // we don't refill here in that case. if (state != ComboBoxState.Disabled) { Color windowColor = visualStyleRenderer.GetColor(ColorProperty.FillColor); if (windowColor != SystemColors.Window) { Rectangle fillRect = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); fillRect.Inflate(-2, -2); //then we need to re-fill the background. g.FillRectangle(SystemBrushes.Window, fillRect); } } }
public static void DrawButton(Graphics g, Rectangle bounds, bool focused, PushButtonState state) { Rectangle backgroundContentRectangle; if (RenderWithVisualStyles) { InitializeRenderer((int)state); visualStyleRenderer.DrawBackground(g, bounds); backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); } else { ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state)); backgroundContentRectangle = Rectangle.Inflate(bounds, -3, -3); } if (focused) { ControlPaint.DrawFocusRectangle(g, backgroundContentRectangle); } }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (g == null) { base.OnPaint(e); return; } Rectangle rectClient = this.ClientRectangle; int nNormalizedPos = m_nPosition - m_nMinimum; int nNormalizedMax = m_nMaximum - m_nMinimum; Rectangle rectDraw; if (VisualStyleRenderer.IsSupported) { VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.ProgressBar.Bar.Normal); vsr.DrawBackground(g, rectClient); rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient); } else { g.FillRectangle(SystemBrushes.Control, rectClient); g.DrawLine(Pens.Gray, 0, 0, rectClient.Width - 1, 0); g.DrawLine(Pens.Gray, 0, 0, 0, rectClient.Height - 1); g.DrawLine(Pens.White, rectClient.Width - 1, 0, rectClient.Width - 1, rectClient.Height - 1); g.DrawLine(Pens.White, 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); } Rectangle rectGradient = new Rectangle(rectDraw.X, rectDraw.Y, rectDraw.Width, rectDraw.Height); if ((rectGradient.Width & 1) == 0) { ++rectGradient.Width; } int nDrawWidth = (int)((float)rectDraw.Width * ((float)nNormalizedPos / (float)nNormalizedMax)); LinearGradientBrush brush = new LinearGradientBrush(rectGradient, Color.FromArgb(255, 128, 0), Color.FromArgb(0, 255, 0), LinearGradientMode.Horizontal); g.FillRectangle(brush, rectDraw.Left, rectDraw.Top, nDrawWidth, rectDraw.Height); }
/// <summary> /// Method to draw visualstyle themes in case of per-monitor scenarios where Hwnd is necessary /// </summary> /// <param name="g"> graphics object</param> /// <param name="bounds"> button bounds</param> /// <param name="focused"> is focused?</param> /// <param name="state"> state</param> /// <param name="handle"> handle to the control</param> internal static void DrawButtonForHandle(Graphics g, Rectangle bounds, bool focused, PushButtonState state, IntPtr handle) { Rectangle contentBounds; if (RenderWithVisualStyles) { InitializeRenderer((int)state); visualStyleRenderer.DrawBackground(g, bounds, handle); contentBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); } else { ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state)); contentBounds = Rectangle.Inflate(bounds, -3, -3); } if (focused) { ControlPaint.DrawFocusRectangle(g, contentBounds); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.Focused && Application.RenderWithVisualStyles && this.FlatStyle == FlatStyle.Standard) { if (renderer == null) { VisualStyleElement elem = VisualStyleElement.Button.PushButton.Normal; renderer = new VisualStyleRenderer(elem.ClassName, elem.Part, (int)PushButtonState.Normal); } Rectangle rc = renderer.GetBackgroundContentRectangle(e.Graphics, new Rectangle(0, 0, this.Width, this.Height)); rc.Height--; rc.Width--; using (Pen p = new Pen(Brushes.DarkGray)) { e.Graphics.DrawRectangle(p, rc); } } }
public virtual Rectangle GetTabCloseRect(BpTabPage page, Rectangle tab) { if (!IncludesCloseButton(page)) { return(Rectangle.Empty); } Graphics g = CreateGraphics(); VisualStyleRenderer renderer; Rectangle bounds = new Rectangle(tab.X, tab.Y, tab.Width, tab.Height); VisualStyleElement element = GetElement(page); if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { renderer = new VisualStyleRenderer(element); bounds = renderer.GetBackgroundContentRectangle(g, bounds); } bounds.X += SystemInformation.Border3DSize.Width; bounds.Y += SystemInformation.Border3DSize.Height; bounds.Width -= SystemInformation.Border3DSize.Width * 2; bounds.Height -= SystemInformation.Border3DSize.Height * 2; Size closesize; element = VisualStyleElement.ToolTip.Close.Normal; if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { renderer = new VisualStyleRenderer(element); closesize = renderer.GetPartSize(g, ThemeSizeType.Draw); } else { Font closefont = new Font("Marlett", SystemFonts.MenuFont.Size); closesize = TextRenderer.MeasureText("r", closefont); closesize.Height += SystemInformation.Border3DSize.Height * 2; closesize.Width += SystemInformation.Border3DSize.Width * 2; } bounds.X = bounds.Right - closesize.Width; bounds.Width = closesize.Width; bounds.Y += (bounds.Height - closesize.Height) / 2; bounds.Height = closesize.Height; return(bounds); }
private void RemoveButtonFocusBorder_Paint(object sender, PaintEventArgs e) { Button control = (Button)sender; base.OnPaint(e); if (control.Focused && Application.RenderWithVisualStyles && control.FlatStyle == FlatStyle.Flat) { if (renderer == null) { VisualStyleElement elem = VisualStyleElement.Button.PushButton.Normal; renderer = new VisualStyleRenderer(elem.ClassName, elem.Part, (int)PushButtonState.Normal); } Rectangle rc = renderer.GetBackgroundContentRectangle(e.Graphics, new Rectangle(1, 1, control.Width, control.Height)); rc.Height -= 3; rc.Width -= 3; using (Pen p = new Pen(SystemColors.Control)) { e.Graphics.DrawRectangle(p, rc); } } }
/// <summary>Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.</summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data. </param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!Focused || !Application.RenderWithVisualStyles) { return; } if (_renderer == null) { var elem = VisualStyleElement.Button.PushButton.Normal; _renderer = new VisualStyleRenderer(elem.ClassName, elem.Part, (int)PushButtonState.Normal); } var rc = _renderer.GetBackgroundContentRectangle(e.Graphics, new Rectangle(0, 0, Width, Height)); rc.Height--; rc.Width--; using (var p = new Pen(Brushes.Purple)) { e.Graphics.DrawRectangle(p, rc); } }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { var rect = e.ToolStrip.ClientRectangle; if (e.ToolStrip.IsDropDown) { var element = VisualStyleElement.CreateElement("menu", 10, 0); if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(element)) { var renderer = new VisualStyleRenderer(element); var clip = renderer.GetBackgroundContentRectangle(e.Graphics, e.ToolStrip.ClientRectangle); var oldClip = e.Graphics.Clip; e.Graphics.ExcludeClip(clip); renderer.DrawBackground(e.Graphics, rect, e.AffectedBounds); e.Graphics.Clip = oldClip; } else { base.OnRenderToolStripBorder(e); } } }
protected override void OnPaintBackground(PaintEventArgs e) { Brush backBrush = (this.Enabled == true) ? _valueBrush : _disabledBrush; if (TextBoxRenderer.IsSupported) { VisualStyleElement state = (this.Enabled == true) ? VisualStyleElement.TextBox.TextEdit.Normal : VisualStyleElement.TextBox.TextEdit.Disabled; VisualStyleRenderer vsr = new VisualStyleRenderer(state); vsr.DrawBackground(e.Graphics, this.ClientRectangle); Rectangle rectContent = vsr.GetBackgroundContentRectangle(e.Graphics, this.ClientRectangle); e.Graphics.FillRectangle(backBrush, rectContent); this.DrawShared(e); } else { e.Graphics.FillRectangle(backBrush, this.ClientRectangle); this.DrawShared(e); ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, Border3DStyle.Sunken); } }
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 OnPaint(PaintEventArgs pevent) { Image imagestripe = Image; if (NumImages == 1 || imagestripe == null) { base.OnPaint(pevent); } else { Color transparentColor = Color.LightGray; Size imgsize = new Size(imagestripe.Width / NumImages, imagestripe.Height); Point imgstart = new Point(); if (imagestripe is Bitmap) { transparentColor = ((Bitmap)imagestripe).GetPixel(0, imgsize.Height - 1); } PushButtonState state = DetermineState(); if (NumImages >= 2 && state == PushButtonState.Disabled) { imgstart.X = imgsize.Width; } else if (NumImages >= 3 && state == PushButtonState.Pressed) { if (!Checked) { imgstart.X = imgsize.Width * 2; } else if (NumImages >= 4) { imgstart.X = imgsize.Width * 3; } } Rectangle destRect = ClientRectangle; if (ButtonRenderer.IsBackgroundPartiallyTransparent(state)) { ButtonRenderer.DrawParentBackground(pevent.Graphics, destRect, this); } ButtonRenderer.DrawButton(pevent.Graphics, destRect, false, state); InitializeRenderer((int)state); destRect = visualStyleRenderer.GetBackgroundContentRectangle(pevent.Graphics, destRect); Padding imgmargin = Padding; destRect.X += imgmargin.Left; destRect.Width -= imgmargin.Horizontal; destRect.Y += imgmargin.Top; destRect.Height -= imgmargin.Vertical; destRect = Align(imgsize, destRect, ImageAlign); using (ImageAttributes attr = new ImageAttributes()) { if (transparentColor.A == 255) { attr.SetColorKey(transparentColor, transparentColor); } pevent.Graphics.DrawImage(imagestripe, destRect, imgstart.X, imgstart.Y, imgsize.Width, imgsize.Height, GraphicsUnit.Pixel, attr); } } }
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); }
private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e) { TreeNodeLocalItem titem = e.Node as TreeNodeLocalItem; if (titem != null) { VisualStyleElement element = VisualStyleElement.TreeView.Item.Normal; if (e.State.HasFlag(TreeNodeStates.Selected) || titem.IsMultiSelect) { element = e.Node.TreeView.Focused ? VisualStyleElement.TreeView.Item.Selected : VisualStyleElement.TreeView.Item.SelectedNotFocus; } else if (e.State.HasFlag(TreeNodeStates.Hot)) { element = VisualStyleElement.TreeView.Item.Hot; } VisualStyleRenderer vsr = new VisualStyleRenderer("Explorer::TreeView", element.Part, element.State); Point drawLoc = titem.Bounds.Location; var imageSize = treeView.ImageList.ImageSize; drawLoc.X -= imageSize.Width; using (SolidBrush b = new SolidBrush(titem.BackColor)) { e.Graphics.FillRectangle(b, drawLoc.X, drawLoc.Y, titem.Bounds.Width + imageSize.Width, titem.Bounds.Height); } Rectangle textRect = vsr.GetBackgroundContentRectangle(e.Graphics, titem.Bounds); var pixelSize = DpiHelper.LogicalToDeviceUnits(new Size(1, 1)); textRect.Offset(pixelSize.Width, pixelSize.Height); bool disabled = titem.ExItem != null ? !titem.ExItem.IsInWorkspace : false; vsr.DrawText(e.Graphics, textRect, titem.Text, disabled, TextFormatFlags.VerticalCenter | TextFormatFlags.LeftAndRightPadding); ExtendedItem item = titem.ExItem; if (string.IsNullOrEmpty(titem.LocalItem)) { e.Graphics.DrawIcon(TFV.Properties.Resources.TFSServer, new Rectangle(drawLoc, imageSize)); } else { bool isFolder = false; if (item != null) { isFolder = item.ItemType == ItemType.Folder; } else { isFolder = Directory.Exists(titem.LocalItem); } if (isFolder) { e.Graphics.DrawIcon(titem.IsExpanded ? m_folderOpen : m_folderClosed, new Rectangle(drawLoc, imageSize)); } else { e.Graphics.DrawIcon((item != null) ? m_addedFileIcon : m_fileIcon, new Rectangle(drawLoc, imageSize)); } } if (item != null) { if (item.ChangeType.HasFlag(ChangeType.Add)) { imageListOverlays.Draw(e.Graphics, drawLoc, 0); } else if (item.ChangeType.HasFlag(ChangeType.Delete)) { imageListOverlays.Draw(e.Graphics, drawLoc, 3); } else if (item.ChangeType.HasFlag(ChangeType.Rollback)) { imageListOverlays.Draw(e.Graphics, drawLoc, 8); } else if (item.ChangeType.HasFlag(ChangeType.Merge)) { imageListOverlays.Draw(e.Graphics, drawLoc, 5); } else if (item.ChangeType.HasFlag(ChangeType.Edit)) { imageListOverlays.Draw(e.Graphics, drawLoc, 2); } if (!item.IsLatest && item.IsInWorkspace) { imageListOverlays.Draw(e.Graphics, drawLoc, 1); } if (item.HasOtherPendingChange) { imageListOverlays.Draw(e.Graphics, drawLoc, 7); } } } }
/// <summary> /// Calculates the rectangles for the tab area, the client area, /// the display area, and the transformed display area. /// </summary> private void CalculateRectangles() { Rectangle olddisp = displayRectangle; positions.Clear(); Graphics g = this.CreateGraphics(); if (Controls.Count > 0) { int width = Width; width -= tabExpand.Horizontal; tabHeight = 0; rows = 0; int used = 0; int pos = 0; foreach (BpTabPage page in Controls) { VisualStyleElement element; VisualStyleRenderer renderer; Size closebutton = new Size(0, 0); if (IncludesCloseButton(page)) { element = VisualStyleElement.ToolTip.Close.Normal; if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { renderer = new VisualStyleRenderer(element); closebutton = renderer.GetPartSize(g, ThemeSizeType.Draw); } else { Font closefont = new Font("Marlett", SystemFonts.MenuFont.Size); closebutton = TextRenderer.MeasureText("r", closefont); closebutton.Height += SystemInformation.Border3DSize.Height * 2; closebutton.Width += SystemInformation.Border3DSize.Width * 2; } } Size size = page.GetPreferredTabSize(g); size.Height = Math.Max(size.Height, closebutton.Height); size.Width += closebutton.Width; element = GetGuessedElement(page); if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { renderer = new VisualStyleRenderer(element); Rectangle fake = new Rectangle(0, 0, size.Width, size.Height); fake = renderer.GetBackgroundExtent(g, fake); size = new Size(fake.Width, fake.Height); } size.Height += SystemInformation.Border3DSize.Height * 2; size.Width += SystemInformation.Border3DSize.Width * 2; if (size.Width > width) { size.Width = width; } if ((size.Width + used) > width) { rowCounts.Add(pos); rows++; used = 0; pos = 0; } TabPosition position = new TabPosition(rows, used, size, pos); positions[page] = position; tabHeight = Math.Max(tabHeight, size.Height); used += size.Width; pos++; if (page == selectedTab) { selectedRow = rows; } } rowCounts.Add(pos); rows++; tabsRectangle = new Rectangle(0, 0, Width, (rows * tabHeight) + tabExpand.Top); paneRectangle = new Rectangle(0, tabsRectangle.Bottom, Width, Height - tabsRectangle.Bottom); } else { paneRectangle = ClientRectangle; tabsRectangle = Rectangle.Empty; } if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Tab.Pane.Normal)) { VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal); displayRectangle = renderer.GetBackgroundContentRectangle(g, paneRectangle); } else { Padding paneMargin = new Padding(SystemInformation.Border3DSize.Width, SystemInformation.Border3DSize.Height, SystemInformation.Border3DSize.Width, SystemInformation.Border3DSize.Height); displayRectangle = Rectangle.Empty; displayRectangle.Y = paneRectangle.Y + paneMargin.Top; displayRectangle.Height = paneRectangle.Height - paneMargin.Vertical; displayRectangle.X = paneRectangle.X + paneMargin.Left; displayRectangle.Width = paneRectangle.Width - paneMargin.Horizontal; } if (olddisp != displayRectangle) { Invalidate(); PerformLayout(); Update(); } else { Rectangle badrect = tabsRectangle; badrect.Height += tabExpand.Bottom; Invalidate(badrect); Update(); } }
private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e) { TreeNodeServerItem titem = e.Node as TreeNodeServerItem; if (titem != null) { VisualStyleElement element = VisualStyleElement.TreeView.Item.Normal; if (e.State.HasFlag(TreeNodeStates.Selected) || titem.IsMultiSelect) { element = e.Node.TreeView.Focused ? VisualStyleElement.TreeView.Item.Selected : VisualStyleElement.TreeView.Item.SelectedNotFocus; } else if (e.State.HasFlag(TreeNodeStates.Hot)) { element = VisualStyleElement.TreeView.Item.Hot; } VisualStyleRenderer vsr = new VisualStyleRenderer("Explorer::TreeView", element.Part, element.State); Point drawLoc = titem.Bounds.Location; drawLoc.X -= imageListIcons.ImageSize.Width; using (SolidBrush b = new SolidBrush(titem.BackColor)) { e.Graphics.FillRectangle(b, drawLoc.X, drawLoc.Y, titem.Bounds.Width + imageListIcons.ImageSize.Width, titem.Bounds.Height); } Rectangle textRect = vsr.GetBackgroundContentRectangle(e.Graphics, titem.Bounds); var pixelSize = DpiHelper.LogicalToDeviceUnits(new Size(1, 1)); textRect.Offset(pixelSize.Width, pixelSize.Height); bool disabled = titem.ExItem != null ? !titem.ExItem.IsInWorkspace : false; vsr.DrawText(e.Graphics, textRect, titem.Text, disabled, TextFormatFlags.VerticalCenter | TextFormatFlags.LeftAndRightPadding); imageListIcons.Draw(e.Graphics, drawLoc, titem.IsExpanded ? titem.ExpandedImageIndex : titem.CollapsedImageIndex); ExtendedItem item = titem.ExItem; if (item != null) { if (item.ChangeType.HasFlag(ChangeType.Add)) { imageListOverlays.Draw(e.Graphics, drawLoc, 0); } else if (item.ChangeType.HasFlag(ChangeType.Delete)) { imageListOverlays.Draw(e.Graphics, drawLoc, 3); } else if (item.ChangeType.HasFlag(ChangeType.Rollback)) { imageListOverlays.Draw(e.Graphics, drawLoc, 8); } else if (item.ChangeType.HasFlag(ChangeType.Merge)) { imageListOverlays.Draw(e.Graphics, drawLoc, 5); } else if (item.ChangeType.HasFlag(ChangeType.Edit)) { imageListOverlays.Draw(e.Graphics, drawLoc, 2); } if (!item.IsLatest && item.IsInWorkspace) { imageListOverlays.Draw(e.Graphics, drawLoc, 1); } if (item.HasOtherPendingChange) { imageListOverlays.Draw(e.Graphics, drawLoc, 7); } } } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (treeView1.SelectedNode != null) { Graphics g = Graphics.FromHwnd(this.Handle); g.Clear(this.BackColor); TextY = 0; if (VisualStyleInformation.IsSupportedByOS) { DrawText(g, "VisualStyles supported by OS"); } else { DrawText(g, "VisualStyles not supported by OS."); return; } if (VisualStyleInformation.IsEnabledByUser) { DrawText(g, "VisualStyles enabled by user."); } else { DrawText(g, "VisualStyles not enabled by user."); return; } // Create the VisualStyleElement MethodInfo m = (MethodInfo)treeView1.SelectedNode.Tag; VisualStyleElement vse = (VisualStyleElement)m.Invoke(null, null); if (!VisualStyleRenderer.IsElementDefined(vse)) { DrawText(g, treeView1.SelectedNode.Text + " is not defined by the current style."); return; } try { // Create the VisualStyleRenderer if (vsr == null) { vsr = new VisualStyleRenderer(vse); } else { vsr.SetParameters(vse); } // Draw some pretty graphics TextY += 25; vsr.DrawBackground(g, new Rectangle(250, TextY, 25, 25)); vsr.DrawBackground(g, new Rectangle(350, TextY, 50, 50)); vsr.DrawBackground(g, new Rectangle(450, TextY, 50, 50), new Rectangle(450, TextY, 25, 25)); TextY += 75; // Test some other methods DrawText(g, "GetBackgroundContentRectangle: " + vsr.GetBackgroundContentRectangle(g, new Rectangle(300, 0, 300, 50)).ToString()); DrawText(g, "GetBackgroundExtent: " + vsr.GetBackgroundExtent(g, new Rectangle(300, 0, 300, 50)).ToString()); DrawText(g, "GetBoolean: " + vsr.GetBoolean(BooleanProperty.MirrorImage).ToString()); DrawText(g, "GetEnumValue: " + vsr.GetEnumValue(EnumProperty.VerticalAlignment).ToString()); DrawText(g, "GetFilename: " + vsr.GetFilename(FilenameProperty.ImageFile).ToString()); DrawText(g, "GetInteger: " + vsr.GetInteger(IntegerProperty.BorderSize).ToString()); DrawText(g, "GetMargins: " + vsr.GetMargins(g, MarginProperty.CaptionMargins).ToString()); DrawText(g, "GetPartSize: " + vsr.GetPartSize(g, ThemeSizeType.Draw).ToString()); DrawText(g, "GetPoint: " + vsr.GetPoint(PointProperty.MinSize).ToString()); DrawText(g, "GetString: " + vsr.GetString(StringProperty.Text).ToString()); DrawText(g, "GetTextExtent: " + vsr.GetTextExtent(g, "HeyThere!", TextFormatFlags.Default).ToString()); DrawText(g, "GetTextMetrics: " + vsr.GetTextMetrics(g).Ascent.ToString()); DrawText(g, "GetBackgroundRegion: " + vsr.GetBackgroundRegion(g, this.ClientRectangle).GetBounds(g).ToString()); DrawText(g, "HitTestBackground: " + vsr.HitTestBackground(g, this.ClientRectangle, new Point(300, 300), HitTestOptions.Caption).ToString()); DrawText(g, "Author: " + VisualStyleInformation.Author); DrawText(g, "ColorScheme: " + VisualStyleInformation.ColorScheme); DrawText(g, "Company: " + VisualStyleInformation.Company); DrawText(g, "ControlHighlightHot: " + VisualStyleInformation.ControlHighlightHot.ToString()); DrawText(g, "Copyright: " + VisualStyleInformation.Copyright); DrawText(g, "Description: " + VisualStyleInformation.Description); DrawText(g, "DisplayName: " + VisualStyleInformation.DisplayName); DrawText(g, "MinimumColorDepth: " + VisualStyleInformation.MinimumColorDepth.ToString()); DrawText(g, "Size: " + VisualStyleInformation.Size.ToString()); DrawText(g, "SupportsFlatMenus: " + VisualStyleInformation.SupportsFlatMenus.ToString()); DrawText(g, "TextControlBorder: " + VisualStyleInformation.TextControlBorder.ToString()); DrawText(g, "Url: " + VisualStyleInformation.Url); DrawText(g, "Version: " + VisualStyleInformation.Version.ToString()); } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } } }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (g == null) { base.OnPaint(e); return; } int nNormalizedPos = m_nPosition - m_nMinimum; int nNormalizedMax = m_nMaximum - m_nMinimum; Rectangle rectClient = this.ClientRectangle; Rectangle rectDraw; if (VisualStyleRenderer.IsSupported) { VisualStyleRenderer vsr = new VisualStyleRenderer( VisualStyleElement.ProgressBar.Bar.Normal); vsr.DrawBackground(g, rectClient); rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient); } else { g.FillRectangle(SystemBrushes.Control, rectClient); g.DrawLine(Pens.Gray, 0, 0, rectClient.Width - 1, 0); g.DrawLine(Pens.Gray, 0, 0, 0, rectClient.Height - 1); g.DrawLine(Pens.White, rectClient.Width - 1, 0, rectClient.Width - 1, rectClient.Height - 1); g.DrawLine(Pens.White, 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); } Rectangle rectGradient = new Rectangle(rectDraw.X, rectDraw.Y, rectDraw.Width, rectDraw.Height); if ((rectGradient.Width & 1) == 0) { ++rectGradient.Width; } int nDrawWidth = (int)((float)rectDraw.Width * ((float)nNormalizedPos / (float)nNormalizedMax)); 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.Control); } bool bRtl = (this.RightToLeft == RightToLeft.Yes); if (bRtl) { Color clrTemp = clrStart; clrStart = clrEnd; clrEnd = clrTemp; } using (LinearGradientBrush brush = new LinearGradientBrush(rectGradient, clrStart, clrEnd, LinearGradientMode.Horizontal)) { g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) : rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height); } }