public static void Draw(IDeviceContext dc, Size minSize, Size maxSize, string title, string text, Rectangle titleRect, Rectangle rect, ToolTipIcon icon, Padding padding) { if (Application.RenderWithVisualStyles) { VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal); VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal); balloonRenderer.DrawBackground(dc, rect); if (icon == ToolTipIcon.None) { titleRenderer.DrawText(dc, new Rectangle(padding.Left, padding.Top, rect.Width - (padding.Left + padding.Right), titleRect.Height), title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter); Rectangle balloonTextBounds = new Rectangle(padding.Left, padding.Top + titleRect.Height, rect.Width - (padding.Left + padding.Right), rect.Height - (padding.Top + titleRect.Height + padding.Bottom)); balloonRenderer.DrawText(dc, balloonTextBounds, text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } }
public static void DrawText(IDeviceContext dc, string text, VisualStyleElement element, Font fallbackFont, ref Point location, bool measureOnly, int width) { // For Windows 2000, using Int32.MaxValue for the height doesn't seem to work, so we'll just pick another arbitrary large value // that does work. Rectangle textRect = new Rectangle(location.X, location.Y, width, NativeMethods.IsWindowsXPOrLater ? Int32.MaxValue : 100000); TextFormatFlags flags = TextFormatFlags.WordBreak; if (IsTaskDialogThemeSupported) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); Rectangle textSize = renderer.GetTextExtent(dc, textRect, text, flags); location = location + new Size(0, textSize.Height); if (!measureOnly) { renderer.DrawText(dc, textSize, text, false, flags); } } else { if (!measureOnly) { TextRenderer.DrawText(dc, text, fallbackFont, textRect, SystemColors.WindowText, flags); } Size textSize = TextRenderer.MeasureText(dc, text, fallbackFont, new Size(textRect.Width, textRect.Height), flags); location = location + new Size(0, textSize.Height); } }
private void OnDraw(object sender, DrawToolTipEventArgs e) { // Try to draw using the visual style renderer. if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ToolTip.Standard.Normal)) { var bounds = e.Bounds; var renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Standard.Normal); renderer.DrawBackground(e.Graphics, bounds); var color = renderer.GetColor(ColorProperty.TextColor); var text = e.ToolTipText; using (var textBrush = new SolidBrush(renderer.GetColor(ColorProperty.TextColor))) using (var font = e.Font) { // Fix the positioning of the bounds for the text rectangle. var rendererBounds = new Rectangle(e.Bounds.X + 6, e.Bounds.Y + 2, e.Bounds.Width - 6 * 2, e.Bounds.Height - 2 * 2); if (!text.Contains('\n')) { renderer.DrawText(e.Graphics, rendererBounds, text); } else { var lines = text.Split('\n').Select(l => l.Trim()); var first = lines.First(); var otherLines = Environment.NewLine + String.Join(Environment.NewLine, lines.Skip(1).ToArray()); // Draw the first line. using (var boldFont = new Font(font, FontStyle.Bold)) { e.Graphics.DrawString(first, boldFont, textBrush, rendererBounds.X - 1, rendererBounds.Y - 1); } renderer.DrawText(e.Graphics, rendererBounds, otherLines, false /*drawDisabled*/, TextFormatFlags.Left); } } } else { // Fall back to non-visual style drawing. e.DrawBackground(); e.DrawBorder(); using (var sf = new StringFormat()) { sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(e.ToolTipText, SystemFonts.DialogFont, Brushes.Black, e.Bounds, sf); } } }
public void DrawText(Graphics graphics, StateTypeId state, Rectangle rect, string text) { VisualStyleRenderer r = GetRenderer(state); if (r != null) { r.DrawText(graphics, rect, text); // TODO: disabled } }
public void VisualStyleRenderer_DrawText_InvokeIDeviceContextRectangleStringBoolTextFormatFlags_Success(Rectangle bounds, string textToDraw, bool drawDisabled, TextFormatFlags flags) { // 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); renderer.DrawText(graphics, bounds, textToDraw, drawDisabled, flags); Assert.Equal(0, renderer.LastHResult); }
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { var state = e.State == ListViewItemStates.Selected ? VisualStyleElement.Header.Item.Hot : VisualStyleElement.Header.Item.Normal; var itemRenderer = new VisualStyleRenderer(state); var r = e.Bounds; r.X += 1; itemRenderer.DrawBackground(e.Graphics, r); r.Inflate(-2, 0); var flags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine; itemRenderer.DrawText(e.Graphics, r, e.Header.Text, false, flags); }
private void PaintAccountGlyph(Graphics g, Rectangle bounds, Account account) { String fullAddress = account.FullAddress ?? "<account error>"; Bitmap image = account.Type == AccountTypes.Regular ? _iconStandard : _iconApps; int tileWidth = _userFrame.Width; int tileHeight = (int)(((float)tileWidth / (float)image.Width) * image.Height); RectangleF clipRect = new RectangleF(bounds.X + 14, bounds.Y + 13, _userFrame.Width - 30, _userFrame.Height - 30); g.SetClip(clipRect); g.DrawImage(image, bounds.X, bounds.Y + 10, tileWidth, tileHeight); g.ResetClip(); g.DrawImage(_userFrame, new Rectangle(bounds.X, bounds.Y, _userFrame.Width, _userFrame.Height)); Point addressPoint = new Point(bounds.X + _userFrame.Width, bounds.Y); Rectangle addressRect = new Rectangle(addressPoint.X, addressPoint.Y, bounds.Width - _userFrame.Width, bounds.Height); Rectangle textExtent = _rendererListSmall.GetTextExtent(g, addressRect, fullAddress, TextFormatFlags.Left); int center = (_userFrame.Height - textExtent.Height) / 2; if (account.Default) { Rectangle defaultExtent = _rendererListSmall.GetTextExtent(g, addressRect, Locale.Current.JumpList.DefaultAccount, TextFormatFlags.Left); center -= (defaultExtent.Height / 2) + 4; // 4 is the additional padding we're adding } addressRect.Offset(0, center); _rendererListSmall.DrawText(g, addressRect, fullAddress, false, TextFormatFlags.Left); if (account.Default) { addressRect.Offset(0, textExtent.Height + 4); _rendererListSmall.DrawText(g, addressRect, Locale.Current.JumpList.DefaultAccount, true, TextFormatFlags.Left); } }
public void DrawHintText(string text) { const int PADDING = 4; renderer.DrawText( graphics, new Rectangle( PADDING, PADDING, size.Width - PADDING, size.Height - PADDING ), text, false, TextFormatFlags.TextBoxControl ); }
//public new String Text { // get { // return base.Text; // } // set { // base.Text = value; // Invalidate(); // } //} protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; // less typing, im lazy. if (_themeElement == null || !VisualStyleRenderer.IsSupported) { using (Brush brush = new SolidBrush(this.ForeColor)) { g.DrawString(this.Text, this.Font, brush, new PointF(0, 0)); } return; } Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height); _renderer.DrawText(g, bounds, this.Text, !this.Enabled, TextFormatFlags.Default); }
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.) } }
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); } } } }
protected override void OnPaint(PaintEventArgs e) { #if AdvancedLogging try { Log.Logger.EnterMethod(this, "OnPaint(PaintEventArgs e)"); #endif if(_Checked) { if(renderer != null) { Rectangle cr = base.ContentRectangle; Image img = Image; // Compute the center of the item's ContentRectangle. var centerY = (int)((cr.Height - img.Height * Environment.Dpi / 96) / 2); var fullRect = new Rectangle(0, 0, Width, Height); var imageRect = new Rectangle( ContentRectangle.Left, ContentRectangle.Top + (int)(centerY * Environment.Dpi / 96), (int)(base.Image.Width * Environment.Dpi / 96), (int)(base.Image.Height * Environment.Dpi / 96)); var textRect = new Rectangle( ContentRectangle.Left + (int)(imageRect.Width * Environment.Dpi / 96), ContentRectangle.Top, ContentRectangle.Width - (int)((imageRect.Width + 10) * Environment.Dpi / 96), ContentRectangle.Height); renderer.DrawBackground(e.Graphics, fullRect); renderer.DrawText(e.Graphics, textRect, Text); renderer.DrawImage(e.Graphics, imageRect, Image); } else { base.OnPaint(e); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(40, SystemColors.Control)), 0, 0, Width, Height); e.Graphics.DrawLines(SystemPens.ControlDark, new[] { new Point(0, ButtonBounds.Height), new Point(0, 0), new Point(ButtonBounds.Width, 0) }); e.Graphics.DrawLines(SystemPens.ControlLight, new[] { new Point(ButtonBounds.Width, 0), new Point(ButtonBounds.Width, ButtonBounds.Height), new Point(0, ButtonBounds.Height) }); } } else { base.OnPaint(e); } #if AdvancedLogging } finally { Log.Logger.LeaveMethod(this, "OnPaint(PaintEventArgs e)"); } #endif }
private void ReDrawTabs(Graphics graphics, Rectangle cliprectangle) { if (!this.Visible) { return; } // Draw tab page TabRenderer.DrawTabPage(graphics, this.ClientRectangle); // If there is no tabs to draw, return if (this.TabCount == 0) { return; } // Check tab alignment switch (this.Alignment) { case TabAlignment.Bottom: graphics.RotateTransform(180); break; case TabAlignment.Left: graphics.RotateTransform(90); break; case TabAlignment.Right: graphics.RotateTransform(-90); break; case TabAlignment.Top: default: break; } // Draw tabs Rectangle tabRectangle; VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal); //TabItemState state; for (int i = 0; i < this.TabCount; ++i) { tabRectangle = this.GetTabRect(i); if (i == this.SelectedIndex) { renderer.SetParameters(VisualStyleElement.Tab.TabItem.Hot); //state = TabItemState.Selected; } else { renderer.SetParameters(VisualStyleElement.Tab.TabItem.Normal); //if(this.TabPages[i].Focused) // state = TabItemState.Hot; //else // state = TabItemState.Normal; } renderer.DrawBackground(graphics, tabRectangle); renderer.DrawText(graphics, tabRectangle, this.TabPages[i].Text); //graphics.FillRectangle(Brushes.Red, tabRectangle); //TabRenderer.DrawTabItem(graphics, this.ClientRectangle, state); } }
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); } } } }
public override void DrawText(Graphics graphics, Rectangle bounds, string text) { _renderer.DrawText(graphics, bounds, text, false, TextFormatFlags.EndEllipsis); }
/// <summary> /// Raises the 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); try { // Setup variables var useVs = rnd != null && Application.RenderWithVisualStyles; var r = DeflateRect(ClientRectangle, Padding); var tff = this.BuildTextFormatFlags(); Rectangle tRect, iRect; ExtensionMethods.CalcImageAndTextBounds(r, Text, Font, Image, TextAlign, ImageAlign, TextImageRelation, !AutoSize, 0, ref tff, out tRect, out iRect); // Draw background if (SupportGlass && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled()) { e.Graphics.Clear(Color.Black); } else { if (useVs) { rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle); } else { e.Graphics.Clear(BackColor); } } // Draw image if (Image != null) { if (useVs) { rnd.DrawImage(e.Graphics, iRect, Image); } else { e.Graphics.DrawImage(Image, iRect); } } // Draw text if (Text.Length > 0) { var rtl = this.GetRightToLeftProperty(); if (useVs) { if (rtl == RightToLeft.Yes) { tff |= TextFormatFlags.RightToLeft; } if (GlowingText) { rnd.DrawGlowingText(e.Graphics, tRect, Text, Font, ForeColor, tff); } else { rnd.DrawText(e.Graphics, tRect, Text, !Enabled, tff); } } else { var br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText; var sf = new StringFormat(StringFormat.GenericDefault); if (rtl == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } e.Graphics.DrawString(Text, Font, br, ClientRectangle, sf); } } } catch { } }