Two things I noticed:
1. You're overriding the WndProc to detect when the form loses focus? Any particular reason why you're not using the Deactivated event?
2. You're setting the font manually to Segoe UI, 9pt. Instead of doing that, I recommend setting it to SystemFonts.IconTitleFont (do this in the constructor
after calling InitializeComponents, or do it in the Load event; the latter is required if you don't want to do it in DesignMode (which is what I do). This has the advantage of using Segoe UI on Vista, Tahoma on XP, and Sans Serif elsewhere, and it
also obeys the user's font size settings.
I have a class that I use as the base class for most of my forms that does this for me:
/// Base class for windows forms that should follow the global font scheme settings.
/// This class makes sure the form uses Tahoma on XP and Segoe UI on Vista. Please make sure your
/// form's <see cref="System.Windows.Forms.ContainerControl.AutoScaleMode" /> property is set to
/// Font, and make special provisions if your form uses graphics or anything like that.
public class AutoFontForm : Form
/// Creates a new instance of the <see cref="AutoFontForm" /> class.
this.Load += new EventHandler(AutoFontForm_Load);
void AutoFontForm_Load(object sender, EventArgs e)
if( !DesignMode )
Font = System.Drawing.SystemFonts.IconTitleFont;
Microsoft.Win32.SystemEvents.UserPreferenceChanged += new Microsoft.Win32.UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
There's some issues with graphics since automatic scaling will also resize your pictureboxes if you have any, and you definitely need to test with all three fonts and different sizes (since MS Sans Serif, Tahoma and Segoe UI have wildly different font metrics),
but other than that it works great.