Saturday, August 8, 2009

How to Set your screen resolution in .net application [C#]


Sometimes we need change the screen resolution for running our .net desktop application
So here is the code from where we can change the screen resolution with the help of
proc.StartInfo.Arguments = "/x 800 /y 600"; // this will change the screen resolution to
800x600
using System;
using System.Windows.Forms;
using System.Diagnostics;
class Test
{
static void Main()
{
Screen scr = Screen.PrimaryScreen;
int oldWidth = scr.Bounds.Width;
int oldHeight = scr.Bounds.Height;
Process proc = new Process();
proc.StartInfo.FileName = @"c:\qres\ApplicationName.exe"; // put full path in here
proc.StartInfo.Arguments = "/x 800 /y 600"; // say
proc.Start();
proc.WaitForExit();
Console.WriteLine("Press enter to change back to original resolution and exit program");
Console.ReadLine();
proc.StartInfo.Arguments = "/x " + oldWidth.ToString() + "/y "+ oldHeight.ToString();
proc.Start();
proc.WaitForExit();
}
}

3 comments:

  1. Hi...
    Nice Work...
    Upload All The Rear Code's Of Our Every projects...

    ReplyDelete
  2. Thanks a lot.....

    ReplyDelete