<?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>Blog &#124; BenHollis.net &#187; Windows Forms</title>
	<atom:link href="http://benhollis.net/blog/tags/windows-forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://benhollis.net/blog</link>
	<description>News about BenHollis.net and articles about Ben&#039;s interests</description>
	<lastBuildDate>Fri, 04 Jun 2010 05:39:10 +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>WebLinkLabel Windows Forms Control</title>
		<link>http://benhollis.net/blog/2007/09/09/weblinklabel-windows-forms-control/</link>
		<comments>http://benhollis.net/blog/2007/09/09/weblinklabel-windows-forms-control/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 23:43:38 +0000</pubDate>
		<dc:creator>Ben Hollis</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://brh.numbera.com/blog/index.php/2007/09/09/weblinklabel-windows-forms-control/</guid>
		<description><![CDATA[While I was updating my PopupNotify control today, I realized that I had created another useful little control for XBList that I hadn&#8217;t released, the WebLinkLabel Control. This simple control wraps the standard LinkLabel control to make it easier to embed multiple hyperlinks in a label, each of which will load up a URL in [...]]]></description>
			<content:encoded><![CDATA[<p>While I was <a href="http://brh.numbera.com/blog/index.php/2007/09/09/new-version-of-the-popupnotify-windows-forms-control/">updating my PopupNotify control</a> today, I realized that I had created another useful little control for <a href="http://brh.numbera.com/software/xblist/">XBList</a> that I hadn&#8217;t released, the <a href="http://brh.numbera.com/components/winforms/weblinklabel/">WebLinkLabel Control</a>. This simple control wraps the standard <a href="http://msdn2.microsoft.com/en-us/library/897fcdkf.aspx">LinkLabel</a> control to make it easier to embed multiple hyperlinks in a label, each of which will load up a URL in the user&#8217;s default browser when clicked. It&#8217;s not the most complex thing in the world, but it has proven useful for inserting help links into XBList&#8217;s error dialogs, so I suspect it might be of some utility to others. Using it is about as simple as using a standard Label. Just drag the WebLinkLabel onto your form, customize it however you like, then assign a specially-formatted string to the <tt>Text</tt> property. You use &#8220;url&#8221; tags to specify where you want links, like this: &#8220;Hello, this is text &lt;url=http://brh.numbera.com&gt;with a link in it&lt;/url&gt;.&#8221; You can of course have as many links, pointing to as many different URLs, as you would like. If you want to get that formatted string back out, use the <tt>LinkText</tt> property, or if you want to get a flattened view out (&#8220;Hello, this is text with a link in it.&#8221;), use the <tt>Text</tt> property.</p>
<p>This code is licensed under the LGPL, like the <a href="http://brh.numbera.com/components/winforms/">other XBList bits</a> I&#8217;ve released. As usual, I would appreciate it if whoever uses this code would email me to let me know how they&#8217;re using it, just for my own amusement. <a href="http://brh.numbera.com/components/winforms/weblinklabel/">You can download the control right here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://benhollis.net/blog/2007/09/09/weblinklabel-windows-forms-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Version of the PopupNotify Windows Forms Control</title>
		<link>http://benhollis.net/blog/2007/09/09/new-version-of-the-popupnotify-windows-forms-control/</link>
		<comments>http://benhollis.net/blog/2007/09/09/new-version-of-the-popupnotify-windows-forms-control/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 22:20:49 +0000</pubDate>
		<dc:creator>Ben Hollis</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[PopupNotify]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://brh.numbera.com/blog/index.php/2007/09/09/new-version-of-the-popupnotify-windows-forms-control/</guid>
		<description><![CDATA[A couple years back I posted the source of XBList&#8216;s tray notification control on my site as the PopupNotify control. I licensed it under the LGPL so people could use it for their own applications. While I requested that whoever used it should let me know, I&#8217;ve never received any email about it until this [...]]]></description>
			<content:encoded><![CDATA[<p>A couple years back I posted the source of <a href="http://brh.numbera.com/software/xblist/">XBList</a>&#8216;s tray notification control on my site as the <a href="http://brh.numbera.com/components/winforms/popupnotify/">PopupNotify</a> control. I licensed it under the LGPL so people could use it for their own applications. While I requested that whoever used it should let me know, I&#8217;ve never received any email about it until this week, when somebody wrote to tell me that they had been using it but it didn&#8217;t work on Vista, and they wanted some help getting it to work. Despite the fact that I would rather they had told me about this beforehand, I&#8217;ve taken this as an opportunity to update the component. I just pulled out the current version of the control that I&#8217;m using for XBList, which has a much prettier Vista-style look, less P/Invoke calls, and other .NET 2.0 improvements. I&#8217;ve left the 1.1 version of the control around for anyone who wants to use it but hasn&#8217;t updated to .NET 2.0 yet.</p>
<p class="blogimage"><a href="http://brh.numbera.com/components/winforms/popupnotify/"><img src='http://brh.numbera.com/blog/wp-content/uploads/2007/09/justthepopup.jpg' alt='The new, Vista-style popup' /></a></p>
<p>Hopefully this component will continue to be useful to other developers, and they&#8217;ll let me know if they&#8217;re using it in their projects, since it&#8217;s just so much more fun to release stuff for free when you get to see it in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://benhollis.net/blog/2007/09/09/new-version-of-the-popupnotify-windows-forms-control/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Setting the correct default font in .NET Windows Forms apps</title>
		<link>http://benhollis.net/blog/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/</link>
		<comments>http://benhollis.net/blog/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/#comments</comments>
		<pubDate>Wed, 11 Apr 2007 09:05:17 +0000</pubDate>
		<dc:creator>Ben Hollis</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[Windows Vista]]></category>

		<guid isPermaLink="false">http://brh.numbera.com/blog/index.php/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/</guid>
		<description><![CDATA[I was working on XBList the other night when I realized something - the font used in its dialogs and the friends list wasn't Segoe UI. Segoe UI is the very pretty, ClearType-optimized new default dialog font in Windows Vista. In Windows XP and 2000, it's Tahoma, and in earlier editions it was Microsoft Sans [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on <a href="http://brh.numbera.com/software/xblist/">XBList</a> the other night when I realized something - the font used in its dialogs and the friends list wasn't <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/uxguide/uxguide/Resources/WhatsNewInVista/fonts.asp">Segoe UI</a>. Segoe UI is the very pretty, ClearType-optimized new default dialog font in Windows Vista. In Windows XP and 2000, it's Tahoma, and in earlier editions it was Microsoft Sans Serif. You can see the subtle differences between them:</p>
<p class="blogimage"><img src='http://brh.numbera.com/blog/wp-content/uploads/2007/04/ms_system_fonts.png' alt='Microsoft System Fonts' /></p>
<p>In .NET and Windows Forms, the default font for controls is actually Microsoft Sans Serif, not the operating system's default dialog font! <a href="http://weblogs.asp.net/kdente/archive/2005/03/13/394499.aspx">Kevin Dente explains this on his blog.</a> This is not the only time Microsoft's dropped the ball on this - if you go through some dialogs in Vista you'll see that many of them use Tahoma or even Microsoft Sans Serif instead of Segoe UI. This is pretty funny, especially when Rule #1 of the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/uxguide/uxguide/Resources/TopRules/TopRules.asp">Top Rules for the Windows Vista User Experience</a> is "Use the Aero Theme and System Font (Segoe UI)". <a href="http://blogs.msdn.com/michkap/archive/2006/06/11/626100.aspx">Mitch Kaplan offers up a pretty good explanation</a> for why getting it all right is very hard, but having a mix of old and new fonts still looks shoddy. </p>
<p>I don't want my apps to look shoddy. Embarrassingly enough, I've been hardcoding Tahoma in all my apps to get the more "modern" XP look.  Now that Vista's on the scene, it's clear that I want to select the correct default font for whichever OS my app is running on. As Kevin points out, <code>Control.DefaultFont</code> is no help here - it's what's driving Windows Forms' default choice of Microsoft Sans Serif in the first place. After some digging I found <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=115408">this Visual Studio feedback ticket (sign in required)</a>, where the Visual Studio guys explain that, while they couldn't fix the default, they did create a SystemFonts class to help out. They recommend putting this code in your Form's constructor:</p>
<div class="igBar"><span id="lcsharp-3"><a href="#" onclick="javascript:showPlainTxt('csharp-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-3">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Font</span> = SystemFonts.<span style="color: #0000FF;">DialogFont</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">InitializeComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Unfortunately, this doesn't work in a number of ways. The first is that on Vista, <code>SystemFonts.DialogFont</code> is... Tahoma! Closer, but not quite right yet. If you pop open SystemFonts in <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a>, you'll see that the DialogFont property just does some simple platform-detection, and then just hardcodes Tahoma. This worked when it was just 2000/XP vs. 9x, but Vista throws it for a total loop. Fortunately the fix is easy - use <code>SystemFonts.MessageBoxFont</code> instead. This one seems to always return the correct default dialog font. </p>
<p>However, I ran into one more problem. If I set the default font on the Form, like the code above does, I get weird, bloated controls:</p>
<p class="blogimage"><img src='http://brh.numbera.com/blog/wp-content/uploads/2007/04/segoe_bad.png' alt='Setting the default font on the form screws up controls' /></p>
<p>Fortunately I've got a solution for that one too. Instead of setting the font on the Form and letting it inherit, just loop through the <code>Controls</code> property, and individually set the right font on each control:</p>
<div class="igBar"><span id="lcsharp-4"><a href="#" onclick="javascript:showPlainTxt('csharp-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-4">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">// Set the default dialog font on each child control</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Control c <span style="color: #0600FF;">in</span> Controls<span style="color: #000000;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; c.<span style="color: #0000FF;">Font</span> = SystemFonts.<span style="color: #0000FF;">MessageBoxFont</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">// Use a larger, bold version of the default dialog font for one control</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">label1</span>.<span style="color: #0000FF;">Font</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Font<span style="color: #000000;">&#40;</span>SystemFonts.<span style="color: #0000FF;">MessageBoxFont</span>.<span style="color: #0000FF;">Name</span>, 12f, FontStyle.<span style="color: #0000FF;">Bold</span>, GraphicsUnit.<span style="color: #0000FF;">Point</span><span style="color: #000000;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now I get a more familiar-looking dialog:</p>
<p class="blogimage"><img src='http://brh.numbera.com/blog/wp-content/uploads/2007/04/segoe_good.png' alt='Setting the default font on each control looks fine' /></p>
<p>I could always make a subclass of Form to do this for me, but I'm OK with copying it into each new form. With this code, all my controls come up with the pretty new Segoe UI font in Windows Vista, and Tahoma in XP. </p>
]]></content:encoded>
			<wfw:commentRss>http://benhollis.net/blog/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
