Category Archive: Code

Oct 20

Which timer can I use in my WPF or Silverlight application?

Instead of System.Timers.Timer you should use DispatcherTimer. You can find it in the System.Windows.Threading namespace. using System.Windows.Threading; DispatcherTimer timer; timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(5); timer.Tick += new EventHandler(this.TimerTick); timer.Start();

Oct 12

How do I retrieve command-line arguments in my WPF application?

The easiest way to retrieve command-line arguments in any (not just WPF) .NET application is to simply call System.Environment.GetCommandLineArgs(). And you can do that at any point in your application not just from the Main method. using System; class Sample { public static void Main() { Console.WriteLine(); String[] arguments = Environment.GetCommandLineArgs(); Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", …

Continue reading »

Oct 09

How can I get the size of primary screen in C#?

Sometimes you would like to set the window to have the same dimensions as the primary screen but without covering the taskbar. Or you would like to maximize a bordeless (WindowStyle=none) window (again without covering the taskbar). The following code does just that. Window win; … win.Height = SystemParameters.MaximizedPrimaryScreenHeight; win.Width = SystemParameters.MaximizedPrimaryScreenWidth;

» Newer posts