locked
Screen Resolution Change RRS feed

Answers

  • Looks like the links code were not working becasue i was using a Vista but when i try this with Xp it works peetty good.
    Does anyone know why it was not working with Vista
    जिन्दगी किसान भयो यार
    • Proposed as answer by OK24 Friday, June 6, 2008 1:44 PM
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 8:03 AM
    Friday, June 6, 2008 1:44 PM
  • Hi.  I had gotten this code snippet from another thread (can't recall the source now) but it works pretty well.  It requires using the DirectX 7 library.   I used it in an app at my work and it it did the job perfectly.  No idea if it works with Vista though...

     Private dx As New DirectX7  
        Private dd As DirectDraw7  
        Friend OriginalResHeight As Int32 = 600 
        Friend OriginalResWidth As Int32 = 800 
        Friend OriginalResDepth As Int32 = 32  
        Friend NewResHeight As Int32 = 768 
        Friend NewResWidth As Int32 = 1024 
        Friend NewResDepth As Int32 = 32  
        Private HasResolutionChanged As Boolean = False 
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
            If My.Computer.Screen.Bounds.Width < 1024 Then  
                OriginalResHeight = My.Computer.Screen.Bounds.Height  
                OriginalResWidth = My.Computer.Screen.Bounds.Width  
                OriginalResDepth = My.Computer.Screen.BitsPerPixel  
                ChangeRes(NewResWidth, NewResHeight, NewResDepth)  
            End If  
     
            Me.Location = New Point((NewResWidth / 2) - (Me.Width / 2), (NewResHeight / 2) - (Me.Height / 2))  
        End Sub  
     
        Private Sub frmMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed  
     
            If HasResolutionChanged Then  
                Try  
                    ChangeRes(OriginalResWidth, OriginalResHeight, OriginalResDepth)  
                    dd.RestoreDisplayMode()  
                Catch ex As Exception  
                Finally  
                    ReleaseComObject(dd)  
                    ReleaseComObject(dx)  
                    dd = Nothing 
                    dx = Nothing 
                    GC.Collect()  
               End Try  
            End If  
        End Sub  
     
        Friend Sub ChangeRes(ByVal width As Int32, ByVal height As Int32, ByVal depth As Int32)  
     
            Try  
                dd = dx.DirectDrawCreate("")  
                dd.SetDisplayMode(width, height, depth, 0, 0)  
                HasResolutionChanged = True 
            Catch ex As Exception  
                MessageBox.Show("Cannot change the screen resolution.")  
            End Try  
     
        End Sub 
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 8:03 AM
    Friday, June 6, 2008 6:04 PM

All replies


  • Vulpes (at CsharpFriends) gave the following advice. The control panel doesn't allow full control over the number of pixels (it doesn't allow "midrange" resolution).  If you need that, download the QRes utility,
        http://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/QRes.shtml
    You can also use  itfrom the command line, or you can have C# execute it from the command line like this:
    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\qres.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();
        }
    }


    Well, after I changed the resolution, the font got ugly. Vulpes commented on this:
    "This can happen if you're running a high resolution monitor below its optimum resolution. One thing that may work is to increase the Windows DPI setting so that it more closely matches the resolution of the display. This should make text easier to read. To do this, go to Control Panel -> Display-> Settings tab -> Advanced and then increase the DPI from 96 to 120 or whatever options you have on there.
    If it's no better, I'd try changing the size of the font from the Appearance tab."


    Friday, June 6, 2008 2:15 AM
  • do you have any efficient code with vb net because , i wanted to change the screen resolution to higher resolution for my app if user has lower resolution as my forms and controls gets weired with low resolution.  i have aslo tried http://forums.msdn.microsoft.com/en-US/vbgeneral/thread/347be7c2-3851-4775-bad5-4b9b7cd06677
    but throws some stack errors

    जिन्दगी किसान भयो यार
    Friday, June 6, 2008 4:30 AM
  • Looks like the links code were not working becasue i was using a Vista but when i try this with Xp it works peetty good.
    Does anyone know why it was not working with Vista
    जिन्दगी किसान भयो यार
    • Proposed as answer by OK24 Friday, June 6, 2008 1:44 PM
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 8:03 AM
    Friday, June 6, 2008 1:44 PM
  • Hi,

    This page explains how to change the resolution:
    http://msdn.microsoft.com/en-us/library/ms812499.aspx

    You will have to make some api calls, but i'm sure when you'll google you'll find ppl who have done this before.

    Ralf


    Friday, June 6, 2008 2:18 PM
  • Hi.  I had gotten this code snippet from another thread (can't recall the source now) but it works pretty well.  It requires using the DirectX 7 library.   I used it in an app at my work and it it did the job perfectly.  No idea if it works with Vista though...

     Private dx As New DirectX7  
        Private dd As DirectDraw7  
        Friend OriginalResHeight As Int32 = 600 
        Friend OriginalResWidth As Int32 = 800 
        Friend OriginalResDepth As Int32 = 32  
        Friend NewResHeight As Int32 = 768 
        Friend NewResWidth As Int32 = 1024 
        Friend NewResDepth As Int32 = 32  
        Private HasResolutionChanged As Boolean = False 
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
            If My.Computer.Screen.Bounds.Width < 1024 Then  
                OriginalResHeight = My.Computer.Screen.Bounds.Height  
                OriginalResWidth = My.Computer.Screen.Bounds.Width  
                OriginalResDepth = My.Computer.Screen.BitsPerPixel  
                ChangeRes(NewResWidth, NewResHeight, NewResDepth)  
            End If  
     
            Me.Location = New Point((NewResWidth / 2) - (Me.Width / 2), (NewResHeight / 2) - (Me.Height / 2))  
        End Sub  
     
        Private Sub frmMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed  
     
            If HasResolutionChanged Then  
                Try  
                    ChangeRes(OriginalResWidth, OriginalResHeight, OriginalResDepth)  
                    dd.RestoreDisplayMode()  
                Catch ex As Exception  
                Finally  
                    ReleaseComObject(dd)  
                    ReleaseComObject(dx)  
                    dd = Nothing 
                    dx = Nothing 
                    GC.Collect()  
               End Try  
            End If  
        End Sub  
     
        Friend Sub ChangeRes(ByVal width As Int32, ByVal height As Int32, ByVal depth As Int32)  
     
            Try  
                dd = dx.DirectDrawCreate("")  
                dd.SetDisplayMode(width, height, depth, 0, 0)  
                HasResolutionChanged = True 
            Catch ex As Exception  
                MessageBox.Show("Cannot change the screen resolution.")  
            End Try  
     
        End Sub 
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 8:03 AM
    Friday, June 6, 2008 6:04 PM