Esempio n. 1
0
 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);
     }
 }
 protected override Rectangle GetBodyTextRect(Graphics dc, string text, Rectangle rect)
 {
     if (IsDefined(VisualStyleElement.ToolTip.Balloon.Normal))
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
         return renderer.GetTextExtent(dc, rect, text, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
     }
     else
     {
         SizeF size = dc.MeasureString(text, SystemFonts.DefaultFont, rect.Size.Width,
             new StringFormat());
         return new Rectangle(new Point(0, 0), Size.Ceiling(size));
     }
 }
 protected override Rectangle GetTitleTextRect(Graphics dc, string title, Rectangle rect)
 {
     if (IsDefined(VisualStyleElement.ToolTip.BalloonTitle.Normal))
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
         return renderer.GetTextExtent(dc, rect, title, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
     }
     else
     {
         SizeF size = dc.MeasureString(title, new Font(SystemFonts.DefaultFont, FontStyle.Bold), rect.Size.Width,
             new StringFormat(StringFormatFlags.NoWrap));
         return new Rectangle(new Point(0, 0), Size.Ceiling(size));
     }
 }
Esempio n. 4
0
		private void UpdateTheme() {

			if (_themeElement == null) {
				return;
			}

			using (Graphics g = this.CreateGraphics()) {
				_renderer = new VisualStyleRenderer(_themeElement);

				Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height);
				Rectangle textExtent = _renderer.GetTextExtent(g, bounds, this.Text, TextFormatFlags.Default);

				this.Size = this.MinimumSize = new Size(textExtent.Width, textExtent.Height);
			}
		}
Esempio n. 5
0
			protected override void OnPaint(PaintEventArgs e)
			{
				var normal = VisualStyleElement.ToolTip.Standard.Normal;
				if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(normal))
				{
					var renderer = new VisualStyleRenderer(normal);
					renderer.DrawBackground(e.Graphics, ClientRectangle);
					var textExtent = renderer.GetTextExtent(e.Graphics, ClientRectangle, Text, _tfFlags);
					textExtent.X = ClientRectangle.X + ClientRectangle.Width / 2 - textExtent.Width / 2;
					textExtent.Y = ClientRectangle.Y + ClientRectangle.Height / 2 - textExtent.Height / 2;
					renderer.DrawText(e.Graphics, textExtent, Text, false, _tfFlags);
					return;
				}
				e.Graphics.FillRectangle(SystemBrushes.Info, ClientRectangle);
				var pen = SystemInformation.HighContrast ? SystemPens.InfoText : SystemPens.Control;
				e.Graphics.DrawLine(pen, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Top);
				e.Graphics.DrawLine(pen, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Left, ClientRectangle.Bottom);
				e.Graphics.DrawLine(SystemPens.InfoText, ClientRectangle.Left, ClientRectangle.Bottom - 1, ClientRectangle.Right, ClientRectangle.Bottom - 1);
				e.Graphics.DrawLine(SystemPens.InfoText, ClientRectangle.Right - 1, ClientRectangle.Top, ClientRectangle.Right - 1, ClientRectangle.Bottom);
				var crect = ClientRectangle;
				crect.Inflate(-2, -2);
				TextRenderer.DrawText(e.Graphics, Text, Font, crect, SystemColors.InfoText, _tfFlags);
			}
Esempio n. 6
0
			public SizeF method_0(string text)
			{
				SizeF result;
				using (var graphics = CreateGraphics())
				{
					var normal = VisualStyleElement.ToolTip.Standard.Normal;
					if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(normal))
					{
						var renderer = new VisualStyleRenderer(normal);
						var textExtent = renderer.GetTextExtent(graphics, text, TextFormatFlags.Default);
						result = renderer.GetBackgroundExtent(graphics, textExtent).Size;
					}
					else
					{
						SizeF sizeF = TextRenderer.MeasureText(graphics, text, Font, new Size(SystemInformation.PrimaryMonitorSize.Width, 2147483647), _tfFlags);
						sizeF.Width -= 2f;
						sizeF.Height += 2f;
						result = sizeF;
					}
				}
				return result;
			}
        public static Rectangle GetBodyRect(IDeviceContext dc, Size minSize, Size maxSize, string text, Rectangle titleRect, ToolTipIcon icon, Padding padding)
        {
            Rectangle ret;
            if (text == null)
            {
                ret = new Rectangle(new Point(0, 0), minSize);
            }
            else
            {
                ret = new Rectangle(new Point(0, 0), maxSize);
                ret.Width -= padding.Horizontal;

                if (Application.RenderWithVisualStyles)
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
                    Rectangle rect = renderer.GetTextExtent(dc, ret, text, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);

                    if (rect.Width + padding.Horizontal > maxSize.Width)
                        ret.Width = maxSize.Width;
                    else if (rect.Width + padding.Horizontal < minSize.Width)
                        ret.Width = minSize.Width;
                    else
                        ret.Width = rect.Width;

                    if (rect.Height > maxSize.Height)
                        ret.Height = maxSize.Height;
                    else
                        ret.Height = rect.Height;

                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            return ret;
        }