Ejemplo n.º 1
0
	private static void MeasureText(ClockItem mi, String[] texts, Graphics g, bool square = false, double extraWFactor = 1.0) {
		g.TextRenderingHint = mi.Font.Size < 20 ? TextRenderingHint.SystemDefault : TextRenderingHint.AntiAlias;
		TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPadding;

		Size ps = Size.Empty;
		String text = null;
		foreach (String t in texts) {	
			Size ps2 = TextRenderer.MeasureText(g, t, mi.Font, Size.Empty, flags);
			ps.Width = (int) (extraWFactor * ps.Width);
			if (ps2.Width > ps.Width) {
				text = t;
				ps.Width = ps2.Width;
			}
			if (ps2.Height > ps.Height)
				ps.Height = ps2.Height;
		}

		ps.Width = (int) Math.Ceiling(extraWFactor * ps.Width);

		if (square) {
			ps.Width = Math.Max(ps.Width, ps.Height);
			ps.Height = ps.Width;
		}

		mi.PreferredSize = ps;
		mi.TextBounds = MeasureString.Measure(text, g, mi.Font, DrawMethod.TextRenderer, flags, new Rectangle(0, 0, ps.Width, ps.Height));
	}
Ejemplo n.º 2
0
	private static void MeasureText(ClockItem mi, String text, Graphics g, bool square = false, double extraWFactor = 1.0) {
		MeasureText(mi, new [] { text }, g, square, extraWFactor);
	}