<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://africadotnet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>http://africadotnet.com/forums/30.aspx</link><description>Other development discussions</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Today's Byte # 2 : Font Manipulation</title><link>http://africadotnet.com/forums/thread/80.aspx</link><pubDate>Wed, 29 Jul 2009 07:56:18 GMT</pubDate><guid isPermaLink="false">bb2961d9-8183-4757-8f93-8f5e67e8c13b:80</guid><dc:creator>Rad</dc:creator><slash:comments>0</slash:comments><comments>http://africadotnet.com/forums/thread/80.aspx</comments><wfw:commentRss>http://africadotnet.com/forums/commentrss.aspx?SectionID=30&amp;PostID=80</wfw:commentRss><description>&lt;p&gt;In the course of your development, you might find that you need to change the font style of a control to somthing like bold or italic.&lt;/p&gt;
&lt;p&gt;Upon investigation, you find that each control has a Font property, that additionally has a boolean Bold property. So you would attempt the following:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;// Set the font to bold&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:&lt;/span&gt; txtName.Font.Bold = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This unfortunately, would fail. Why? Because the Bold property of a font is read only.&lt;/p&gt;
&lt;p&gt;To change the font to bold, you actually need to create a new font, and specify that the new font be created with the style bold. Like so&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;// Change the font to bold, using the existing font&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:&lt;/span&gt; txtName.Font = &lt;span class="kwrd"&gt;new&lt;/span&gt; Font(txtName.Font, FontStyle.Bold);&lt;/pre&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The same thing would apply for italics.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;// Change the font to italic, using the existing font&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:&lt;/span&gt; txtName.Font = &lt;span class="kwrd"&gt;new&lt;/span&gt; Font(txtName.Font, FontStyle.Italic);&lt;/pre&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;An intersting thing to note -- you can also combine the multiple styles. Like so&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;// Change the font to bold, strikeout &amp;amp; italic , using the existing font&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:&lt;/span&gt; txtName.Font = &lt;span class="kwrd"&gt;new&lt;/span&gt; Font(txtName.Font, FontStyle.Italic | FontStyle.Strikeout | FontStyle.Bold);&lt;/pre&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>