A simple little helper static method to easily convert any image to its grayscale counterpart using older WinForms classes (System.Drawing namespace stuff).
Showing posts with label winforms. Show all posts
Showing posts with label winforms. Show all posts
Jan 4, 2011
Dec 19, 2010
Yet another TaskDialog wrapper, this time for WPF!
There are a lot of .NET projects out there for adding TaskDialog support for your Windows applications. They can do this (relatively) easily enough by simply wrapping a lot of calls and types to the Win32 API directly, most importantly the TaskDialogIndirect function and its related TASKDIALOGCONFIG data structure.
Aug 16, 2010
Save user settings on exit
Do you use a Settings file with your Windows Forms application to store user settings like preferences? Would you like it to save those settings to disk after the program closes? Just add the following line to your Main method:
And implement a method like the following:
The key is setting IsBackground to false. By doing this, we're saying that the thread we're kicking off is a foreground thread. This will prevent the process from exiting until that thread exits (i.e. finishes). If you don't do that, the call by Windows to exit the process will kill background threads instead of waiting on them.
Obviously, you can customize this to suit your needs. Saving manually (the OK/Apply button in your Options dialog, perhaps?) or more often automatically might be good practice, too. This is just a really simple example.
Application.ApplicationExit += new EventHandler(Application_SaveSettingsOnExit);
And implement a method like the following:
static void Application_SaveSettingsOnExit(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(Properties.User.Default.Save));
t1.Name = "OnExit";
t1.IsBackground = false;
t1.Start();
}The key is setting IsBackground to false. By doing this, we're saying that the thread we're kicking off is a foreground thread. This will prevent the process from exiting until that thread exits (i.e. finishes). If you don't do that, the call by Windows to exit the process will kill background threads instead of waiting on them.
Obviously, you can customize this to suit your needs. Saving manually (the OK/Apply button in your Options dialog, perhaps?) or more often automatically might be good practice, too. This is just a really simple example.
Subscribe to:
Posts (Atom)