<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bee Eee Blog &#187; c# .Net GUI</title>
	<atom:link href="http://blog.bee-eee.com/tag/c-net-gui/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<lastBuildDate>Wed, 23 Dec 2009 19:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>c# Measuring a String.</title>
		<link>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/</link>
		<comments>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 19:03:13 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[c# .Net GUI]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/</guid>
		<description><![CDATA[Often times it is desirable to draw a string with a System.Drawing.Graphics. My problem came when drawing text over an image. The image itself is dark but had light spots in it. This can make seeing the text very difficult. To fix the problem I fill a box behind the text. To do that I [...]]]></description>
			<content:encoded><![CDATA[<p>Often times it is desirable to draw a string with a <span style="color: green">System.Drawing.Graphics</span>.  My problem came when drawing text over an image.  The image itself is dark but had light spots in it.  This can make seeing the text very difficult.  To fix the problem I fill a box behind the text.  To do that I need to know how tall and wide the text will be.</p>
<p>The magic function is <span style="color: green">Graphics.MeasureString</span>.  This functions returns the calculated size of the string that is being drawn.</p>
<pre class="code">
// measure the string
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
SizeF boundry = g.MeasureString(ToString(), font);

// draw the string
Rectangle textRect = new Rectangle(10, 10, (int)(boundry.Width + 2), (int)(boundry.Height + 2));
g.FillRectangle(Brushes.Black, textRect);
g.DrawRectangle(Pens.White, textRect);
g.DrawString(ToString(), font, Brushes.Yellow, textRect.X, textRect.Y, sf);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
