June 14th, 2007 by Chris
This is a very simple tip that I figured I should post. Its a common thing to want to launch a web browser from your application when a user clicks on a link, or presses a button. The simplest way to perform this is to use the following line of code, that's right, its one single line of code to do it.
C#:
-
System.Diagnostics.Process.Start("http://www.microsoft.com")
Now the benefits of using the above line of code, it will use the users default browser, so if the user has their default browser set to Firefox, then Firefox is launched, if Internet Explorer is the default, then it is used. The key to making sure this works however is to always include the protocol portion of the URL.
Technorati Tags: .net, C#
Posted in Windows Forms | No Comments »
June 12th, 2007 by Chris
As many programmers have come across, sometimes you want to prevent your app being launched more than once. This is a desirable function for many reasons. This can be used when you're app relies on writing or reading from files, and to prevent locking of files and possible corruption, you only want your app to run once. If you're writing something that is going to be only useful in a single instance, you can check and prevent multiple instances being run. The code snippet below details how to perform this check at the launch of your app.
C#:
-
using System;
-
using System.Windows.Forms;
-
public partial class MainDesktop : System.Windows.Window
-
{
-
public MainDesktop()
-
{
-
if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length == 1)
-
{
-
/// App initilization code here
-
}
-
else
-
{
-
this.Close();
-
}
-
}
-
}
Put this code in the main method of your app. This way when it runs, it checks and if finds another process with the same name, causes the new app to close instantly.
Technorati Tags: C#, Windows.Forms, .NET
Posted in Windows Forms | 1 Comment »
June 12th, 2007 by Chris
I've been developing now for the last few months my first WPF application. During this development I've searched for lots of information on how to implement WPF and some of the quirks and workarounds needed to make my app function. My goal is to post some useful links as well as some useful articles of my own to help those with WPF development.
Josh Smith on WPF (A good blog on WPF and some useful articles)
WPF Wonderland (Another good blog on WPF)
WPF Wiki (A wiki for WPF)
MSDN WPF Forums (MSDN forums for WPF discussion)
IRhetoric - Karsten Januszewski (Another WPF blog)
The links above are just a small selection of WPF information out there, since its still a new technology more and more information becomes available, you're best bet is to use these links as a launching platform into the world of WPF.
Technorati Tags: wpf, windows presentation foundation, Microsoft.NET 3.0
Posted in WPF | 1 Comment »