<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Windows Forms Documentation Updates : Form and Application Classes</title><link>http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx</link><description>Tags: Form and Application Classes</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>New White Paper: Creating Smart Application Layouts in Windows Forms 2.0</title><link>http://blogs.msdn.com/winformsue/archive/2006/07/19/671843.aspx</link><pubDate>Thu, 20 Jul 2006 00:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:671843</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/671843.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=671843</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=671843</wfw:comment><description>&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/layWF2.asp"&gt;My new Windows Forms white paper is now available on MSDN&lt;/a&gt;. It covers using ToolStrip as a navigation alternative to TabControl, and creating collapsible flyout menus a la the Visual Studio Toolbox. Compilable code samples are included. &lt;br&gt;&lt;br&gt;Enjoy!&lt;br&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=671843" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Adding Custom My.Application Methods to C# Windows Forms Applications</title><link>http://blogs.msdn.com/winformsue/archive/2006/05/01/587960.aspx</link><pubDate>Tue, 02 May 2006 01:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:587960</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/587960.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=587960</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=587960</wfw:comment><description>&lt;P&gt;In my last entry, I talked about &lt;A HREF="/winformsue/archive/2006/04/28/586193.aspx"&gt;how I loved extending My.Application in VB&lt;/A&gt; to create global methods available to my entire application. &lt;A HREF="/utility/Redirect.aspx?U=http%3a%2f%2fwww.WestchesterDotNet.com"&gt;A reader&lt;/A&gt; mentioned that you can get much of the default functionality associated with the My class by using &lt;A href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;amp;tabid=11#CSharp"&gt;That&lt;/A&gt;. But what about adding your own global functionality?&lt;/P&gt;
&lt;P&gt;You can easily create your own My.Application in a C# Windows Forms app. This provides a central location for application logging and other&amp;nbsp;common tasks. In the following example, I describe how to do this to expose &lt;A HREF="/winformsue/archive/2006/04/26/584559.aspx"&gt;the DataDirectory&amp;nbsp;property I wrote in a previous post&lt;/A&gt;, so that any form or class in your Windows Forms application can discover where the data directory for ClickOnce resides. &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Open Program.cs.&lt;/LI&gt;
&lt;LI&gt;Define a static class named My with a single property named Application:&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;public static class My&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static MyApplication defaultInstance = new CountDownCSharp.MyApplication();&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static MyApplication Application&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (defaultInstance);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Define MyApplication to contain all of the global methods and properties you'll need.&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MyApplication&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String _DataDirectory = null;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public MyApplication()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string GetDataDirectory()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string _PathStr;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ApplicationDeployment.IsNetworkDeployed)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = WinForms.Application.UserAppDataPath;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = WinForms.Application.ExecutablePath.Substring(0, WinForms.Application.ExecutablePath.LastIndexOf("\\"));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(Directory.Exists(_PathStr + "&lt;/FONT&gt;&lt;A href="file://\\images"&gt;&lt;FONT face="Courier New"&gt;\\images&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;")))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = _PathStr + "&lt;/FONT&gt;&lt;A href="file://\\..\\"&gt;&lt;FONT face="Courier New"&gt;\\..\\&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;..";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(Directory.Exists(_PathStr + "&lt;/FONT&gt;&lt;A href="file://\\images"&gt;&lt;FONT face="Courier New"&gt;\\images&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;")))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new DirectoryNotFoundException("Cannot find directory " + _PathStr + "&lt;/FONT&gt;&lt;A href="file://\\images"&gt;&lt;FONT face="Courier New"&gt;\\images&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;. Fatal error.");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (_PathStr);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string DataDirectory&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((_DataDirectory == null))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _DataDirectory = GetDataDirectory();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (_DataDirectory);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (_DataDirectory);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=587960" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>ClickOnce: How to Dynamically Detect Data Directory Between Debug, Release, and Publish</title><link>http://blogs.msdn.com/winformsue/archive/2006/04/26/584559.aspx</link><pubDate>Wed, 26 Apr 2006 17:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:584559</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/584559.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=584559</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=584559</wfw:comment><description>&lt;P&gt;&lt;STRONG&gt;Dynamically Detecting the Data Directory&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;My Slideshow control (&lt;A HREF="/winformsue/archive/2006/02/10/529821.aspx"&gt;which I discussed in a previous post&lt;/A&gt;) looks in a data directory called &lt;STRONG&gt;images&lt;/STRONG&gt; for the images it wishes to display. This adds a curious twist to application development and deployment. When I deploy an application using ClickOnce, I will want to include these files in the data directory for that application. (See &lt;A href="http://msdn2.microsoft.com/en-US/library/d8saf4wy(VS.80).aspx"&gt;Accessing Local and Remote Data in ClickOnce Applications&lt;/A&gt; for the 411 on data directories.) Under ClickOnce, the data directory is a long, garbled path, such as &lt;FONT face="Courier New"&gt;C:\Documents and Settings\&lt;EM&gt;username&lt;/EM&gt;\Local Settings\Apps\2.0\Data\DXQV72TZ.3GR\EERQ26OC.Y91\test..tion_9d0ab10300fca701_0001.0000_edbfed2eeae795d5\Data&lt;/FONT&gt;. I can find the value of this path (deliberately obscured to foil easy discovery of my app's data) by calling &lt;FONT face="Courier New"&gt;Application.UserAppDataPath&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;However&lt;/EM&gt;, when I'm debugging&amp;nbsp;my app&amp;nbsp;in Visual Studio, the data directory path is set to &lt;FONT face="Courier New"&gt;C:\Documents and Settings\&lt;EM&gt;username&lt;/EM&gt;\Application Data\&lt;EM&gt;Publisher Name&lt;/EM&gt;\&lt;EM&gt;App Name&lt;/EM&gt;\&lt;EM&gt;Version Number&lt;/EM&gt;&lt;/FONT&gt;. Now, I could manually stuff my data files in here for the purposes of debugging. Indeed, for most of my project, that's what I did. But this makes it difficult to ship the project to other developers and have it work out of the box. Also, it requires that I switch the files around whenever I&amp;nbsp;update the version, or alter the application&amp;nbsp;or publisher name. The chance that data files will become out of sync during development is high.&lt;/P&gt;
&lt;P&gt;To get around this mess, I wrote a small snippet of code that detects where the data directory resides for the current instance of the application. If ApplicationDeployment.IsNetworkDeployed is true, I use Application.UserAppDataPath as the data directory. If I'm not running as a ClickOnce application, I first look at Application.ExecutablePath to see if the images directory is in the same directory as the executable. If it isn't, I assume I'm running in debug mode under Visual Studio, and look two directories up for my precious data. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Function GetDataDirectory() As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _ExeDir As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _PathStr As String&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If (ApplicationDeployment.IsNetworkDeployed) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = Application.UserAppDataPath &amp;amp; "\images"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Check if it's in the exe directory, or in a debug folder dir.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _ExeDir = Application.ExecutablePath.Substring(0, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.ExecutablePath.LastIndexOf("\"))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = _ExeDir &amp;amp; "\images"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If (Not Directory.Exists(_PathStr)) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _PathStr = _ExeDir &amp;amp; "\..\..\images"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If (Not Directory.Exists(_PathStr)) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Throw New DirectoryNotFoundException("Cannot find directory " &amp;amp; _PathStr &amp;amp; ". Fatal error.")&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetDataDirectory = _PathStr&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This code not only allows the app to switch between debug testing and ClickOnce deployment. It it also supports good ol' xcopy deployment. So long as the &lt;STRONG&gt;images&lt;/STRONG&gt; directory is at the same level as the EXE, I'm good to go. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Populating the Data Directory for ClickOnce Deployment&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How do I add the &lt;STRONG&gt;images&lt;/STRONG&gt; directory and its files to my ClickOnce deployment? As far as Visual Studio is concerned, this is the easy part!&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Right-click your project and select &lt;STRONG&gt;Add-&amp;gt;New Folder...&lt;/STRONG&gt;. In my example, I name my folder &lt;STRONG&gt;images&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Right-click the folder and select &lt;STRONG&gt;Add Existing Items...&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Add all of the items from your folder into the Visual Studio project folder. &lt;/LI&gt;
&lt;LI&gt;Right-click your project again and select &lt;STRONG&gt;Properties&lt;/STRONG&gt;. Click the &lt;STRONG&gt;Publish&lt;/STRONG&gt; tab, and then click the &lt;STRONG&gt;Application Files...&lt;/STRONG&gt; button.&lt;/LI&gt;
&lt;LI&gt;For each of the files you just added, change &lt;STRONG&gt;Publish Status&lt;/STRONG&gt; to &lt;STRONG&gt;Data File&lt;/STRONG&gt;. Leave &lt;STRONG&gt;Download Group&lt;/STRONG&gt; set to &lt;STRONG&gt;(Required)&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=584559" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>Adding Glass to a Windows Forms App on Vista</title><link>http://blogs.msdn.com/winformsue/archive/2006/04/24/582340.aspx</link><pubDate>Mon, 24 Apr 2006 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:582340</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/582340.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=582340</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=582340</wfw:comment><description>&lt;P&gt;Tim Sneath,&amp;nbsp;Windows Vista&amp;nbsp;tech evangelist extraordinaire, has a good post up on &lt;A HREF="/tims/archive/2006/04/18/578637.aspx"&gt;how to add a glass effect to&amp;nbsp;a form in Windows Forms&lt;/A&gt;. It's no more complex than a call into dwmapi.dll - although there are some provisos and quid pro quos, natch.&lt;/P&gt;
&lt;P&gt;It's cool stuff like this that almost makes being a technical evangelist look appealing.&lt;/P&gt;
&lt;P&gt;Almost.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=582340" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>Control.Location is a Pain - or, Why We Need an OffsetLocation() Method</title><link>http://blogs.msdn.com/winformsue/archive/2006/04/20/580039.aspx</link><pubDate>Thu, 20 Apr 2006 20:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:580039</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/580039.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=580039</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=580039</wfw:comment><description>&lt;P&gt;I'm polishing up some code for a Windows Forms white paper on application layouts in Windows Forms 2.0. The paper will cover advanced uses of the ToolStrip control for creating navigational layouts, among other things. One of the samples is a VS Toolbox-style flyout panel. The code to implement this wasn't too gnarly, except that in my first rev, I was new()ing up a whole lotta Point structs in slide-in and slide-out:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;currentControl.Location = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Point(currentControl.Location.X + 20, currentControl.Location.Y)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Jim Galasyn, one of my colleagues on the team, asked why I was doing this. To put it simply, I did it this naively because the Location property of Control is lame. Location is of type Point, which is a struct. Structs are passed by value, not by reference, meaning that returning the Location property directly would pass a copy of the type on the stack. On top of that, for some reason, the source code for Control.Location in Windows Forms just goes ahead and new()s up a new Struct every time you access the Location property anyway! (That's a&amp;nbsp;good reason not to call this property extraneously, and to almost &lt;STRONG&gt;never&lt;/STRONG&gt; call it in&amp;nbsp;large loops.) So direct calls on Location are for naught. &lt;/P&gt;
&lt;P&gt;I worked around this in my own application by caching a Point value, and operating on that using the Offset() method. This eliminated the constant creation of new Point structures on the stack, sped up my app, and make for somewhat cleaner code:&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;_CachedControlPoint.Offset(-20, 0)&lt;BR&gt;currentControl.Location = _CachedControlPoint&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;What's frustrating is that, after 2-1/2 years writing Windows Forms documentation, I &lt;STRONG&gt;still&lt;/STRONG&gt; get bitten by this. It's so natural to call a property or a method and expect that to reflect on the associated object that exceptions such as these throw me for a loop. Sure, we can document this. We &lt;EM&gt;have&lt;/EM&gt; documented it. But documentation can only do so much to defeat logic.&lt;/P&gt;
&lt;P&gt;It would be nice, at the very least, to have an OffsetLocation() method defined on Control that eliminated the need for self-caching of Point objects. I know my product team has bigger fish to fry, but...come on, folks, pretty please? As a favor for l'il ol' me? [insert eyelash-batting here]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=580039" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Boneheaded .NET Error of the Day</title><link>http://blogs.msdn.com/winformsue/archive/2006/03/07/545686.aspx</link><pubDate>Wed, 08 Mar 2006 00:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:545686</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/545686.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=545686</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=545686</wfw:comment><description>&lt;P&gt;[Can I say "boneheaded" on MSDN? If this post disappears in an hour, you'll know I've received an email from HR...]&lt;/P&gt;
&lt;P&gt;As a Programmer/Writer for Windows Forms, I develop code examples in both C# and Visual Basic.NET. Today, I was finishing up a code example for a new SDK topic on ClickOnce and localization. (Yes, I'll be publishing this soon!) I named my C# sample project &lt;FONT face="Courier New"&gt;ClickOnce.SatelliteAssemblies&lt;/FONT&gt;. Wrote, published, tested. Worked like a champ. &lt;/P&gt;
&lt;P&gt;I named my VB.NET sample project &lt;FONT face="Courier New"&gt;ClickOnce.SatelliteAssemblies.VB&lt;/FONT&gt;. Wrote, published, tested...only to find out that the server was prompting me for credentials when it wasn't before. I'd just changed my password, so I assumed&amp;nbsp;the Web server&amp;nbsp;was defaulting to cached credentials. I restarted the Web server, rebooted the box...all to no avail. I was stumped.&lt;/P&gt;
&lt;P&gt;It took an hour and a half for it to dawn on me that my directories ended in the suffix &lt;FONT face="Courier New"&gt;.VB&lt;/FONT&gt;, and that this suffix is, you know, kinda special to a machine with ASP.NET installed on it.&lt;/P&gt;
&lt;P&gt;Sigh.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=545686" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>Calling Validate() and ValidateChildren() from Validating and Validated Events</title><link>http://blogs.msdn.com/winformsue/archive/2006/02/28/540694.aspx</link><pubDate>Tue, 28 Feb 2006 18:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:540694</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/540694.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=540694</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=540694</wfw:comment><description>&lt;P&gt;Don't do it - it won't work. Both methods will automatically return false, in order to prevent infinite recursion from unskillful implementation of the event handlers. I've added a note about this to the relevant sections of the docs.&lt;/P&gt;
&lt;P&gt;Mind you, I'm not entirely clear on why you would &lt;STRONG&gt;want&lt;/STRONG&gt; to do this in the first place. I asked my contact at Product Support Services for the scenario, but haven't heard back. If anyone can shed some light on what problem this is attempting to solve, I'm all ears.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=540694" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>Application.ThreadException sample now works!</title><link>http://blogs.msdn.com/winformsue/archive/2006/02/08/527941.aspx</link><pubDate>Thu, 09 Feb 2006 01:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:527941</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/527941.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=527941</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=527941</wfw:comment><description>&lt;p&gt;Several customers have pointed out to me that the sample for the &lt;a href="http://lab.msdn.microsoft.com/search/Redirect.aspx?title=ThreadException+Event&amp;amp;url=http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassthreadexceptiontopic.asp"&gt;ThreadException&lt;/a&gt; event doesn't even compile, let alone work. Similarly, the topic containing it never clearly differentiated between exceptions on Windows Forms threads (which are handled by ThreadException) and exceptions on other threads (which are handled by &lt;a href="http://lab.msdn.microsoft.com/search/Redirect.aspx?title=AppDomain.UnhandledException+Event+(System)+&amp;amp;url=http://msdn2.microsoft.com/system.appdomain.unhandledexception.aspx"&gt;AppDomain.UnhandledException&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Here's the new sample we'll be including:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Starts the application. &lt;br /&gt;[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]&lt;br /&gt;public static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Add the event handler for handling UI thread exceptions to the event.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set the unhandled exception mode to force all Windows Forms errors to go through&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // our handler.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Add the event handler for handling non-UI thread exceptions to the event. &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AppDomain.CurrentDomain.UnhandledException +=&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Runs the application.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Run(new ErrorHandlerForm());&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Programs the button to throw an exception when clicked.&lt;br /&gt;private void button1_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new ArgumentException("The parameter was invalid");&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Start a new thread, separate from Windows Forms, that will throw an exception.&lt;br /&gt;private void button2_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ThreadStart newThreadStart = new ThreadStart(newThread_Execute);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newThread = new Thread(newThreadStart);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newThread.Start();&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// The thread we start up to demonstrate non-UI exception handling. &lt;br /&gt;void newThread_Execute()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception("The method or operation is not implemented.");&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Handle the UI exceptions by showing a dialog box, and asking the user whether&lt;br /&gt;// or not they wish to abort execution.&lt;br /&gt;private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DialogResult result = DialogResult.Cancel;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = ShowThreadExceptionDialog("Windows Forms Error", t.Exception);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("Fatal Windows Forms Error",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Fatal Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Exit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Exits the program when the user clicks Abort.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (result == DialogResult.Abort)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Exit();&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Handle the UI exceptions by showing a dialog box, and asking the user whether&lt;br /&gt;// or not they wish to abort execution.&lt;br /&gt;// NOTE: This exception cannot be kept from terminating the application - it can only &lt;br /&gt;// log the event, and inform the user about it. &lt;br /&gt;private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exception ex = (Exception)e.ExceptionObject;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string errorMsg = "An application error occurred. Please contact the adminstrator " +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "with the following information:\n\n";&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Since we can't prevent the app from terminating, log this to the event log.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!EventLog.SourceExists("ThreadException"))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EventLog.CreateEventSource("ThreadException", "Application");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create an EventLog instance and assign its source.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EventLog myLog = new EventLog();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLog.Source = "ThreadException";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLog.WriteEntry(errorMsg + ex.Message + "\n\nStack Trace:\n" + ex.StackTrace);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (Exception exc)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("Fatal Non-UI Error",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Fatal Non-UI Error. Could not write the error to the event log. Reason: "&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + exc.Message, MessageBoxButtons.OK, MessageBoxIcon.Stop);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Exit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// Creates the error message and displays it.&lt;br /&gt;private static DialogResult ShowThreadExceptionDialog(string title, Exception e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string errorMsg = "An application error occurred. Please contact the adminstrator " +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "with the following information:\n\n";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return MessageBox.Show(errorMsg, title, MessageBoxButtons.AbortRetryIgnore,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBoxIcon.Stop);&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=527941" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item><item><title>SetCompatibleTextRenderingDefault</title><link>http://blogs.msdn.com/winformsue/archive/2006/01/31/521214.aspx</link><pubDate>Wed, 01 Feb 2006 02:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:521214</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/521214.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=521214</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=521214</wfw:comment><description>&lt;p&gt;There were several changes in Windows Forms for .NET Framework 2.0 that came down the pipe too late for us to document in time for RTM. Once of these was the SetCompatibleTextRenderingDefault() method on System.Windows.Forms.Application. &lt;/p&gt;
&lt;p&gt;I've since documented it; this new text &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault.aspx"&gt;is currently live on MSDN2&lt;/a&gt;. In case you have trouble accessing that, here's what I had to say:&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;Certain Windows Forms controls can render their text using either the GDI graphics library, or the newer GDI+ library. This change was made because of performance and localization issues with GDI+. By default, existing controls that support the &lt;b&gt;UseCompatibleTextRendering&lt;/b&gt; property are set to &lt;b&gt;true&lt;/b&gt; for backwards compatibility, but all new controls in environments such as Visual Studio have this property set to &lt;b&gt;false&lt;/b&gt;. Use &lt;b&gt;SetCompatibleTextRenderingDefault&lt;/b&gt; when you wish to switch the default text rendering for new controls. &lt;/p&gt;
&lt;p&gt;You should never call this method if your Windows Forms code is hosted in another application, such as Internet Explorer. Only call this method in stand-alone Windows Forms applications. &lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;No sample code, since the call is very simple. Just stick this in your Main() method before calling Application.Run(), and you're set.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=521214" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category></item></channel></rss>