locked
Changing display settings using vb.net

    Question

  • Hi All,

     

    I developed a vb.net application. The display of the controls are not correct for all the display settings. If in customer pc any other display setting is there then, the controls are not displaying properly. How to overcome this problem?

     

    Can we change the dispaly settings of the pc using vb.net?

    If yes, any sample code..!

     

    Thank you,

    Narayana Ayyagari.

    Thursday, March 06, 2008 5:44 AM

Answers

  •  

    By display settings if you mean to handle screen resolution, please know that monitor resolution can be checked using following code-

     

    My.Computer.Screen.PrimaryScreen.Bounds.Width

    My.Computer.Screen.PrimaryScreen.Bounds.Height

     

    However changing resolution of screen would require you to use API calls.

     

    Check the following thread for getting more information about it -

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=316763&SiteID=1

     

    -Ajay.

    ---------------------------------

    www.componentone.com

    ---------------------------------

    Friday, March 07, 2008 5:28 AM
  •  Narayana A programmer wrote:

    Hi,

     

    Thanks for u r reply.

    I used Anchor property but, if I install my application in the pc with 1024x768 dislay is ok. If I install in the pc which have 1280x720 the bottom page controls i.e., the controls which are at the bottom cannot be seen.

     

    Thanks,

    Narayana Ayyagari.

     

     

    Right. Anchor won't solve your problem if your form is set to be taller than the user's display settings. If you made your form 768 tall, and the user has his display set to 720 tall, there is no way for him to see the bottom controls.

     

    You can either (1) set the display settings programatically as has already been stated or (2) Set your form to the SMALLEST size that your users will use, using  Anchor so that those  with larger settings get to enjoy the larger sized form. (Use SystemInformation.Working.Area.Width and Height to set the form to fill the screen).

     

    For me, this means I would usually make my form 800x600 (or maybe a few pixels smaller) because most people have the older monitors where this display setting is standard and therefore the form would fit just right.

     

    Realize that if you enlarge the display settings using VB.Net, , this visibly shrinks the controls. They will all fit onscreen but won't be very readable.  If the monitor is a large one, they will still be big enough to be readable. But with a small monitor, the users will get made at you for causing everything to be shrunk.

     

    Anyway, you should use the  QRes utility to change resolution - i only have a C# example:

     

    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 it from 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();

    }

    }

     

    Friday, March 07, 2008 6:08 AM
  • Hi Narayana,

    Based on your post, your application will run in the different resolution machine.

    As far as I know, .net supplies Automatic Scaling mechanism as a solution in this scenario. Automatic scaling enables a form and its controls, designed on one machine with a certain display resolution or system font, to be displayed appropriately on another machine with a different display resolution or system font. It assures that the form and its controls will intelligently resize to be consistent with native windows and other applications on both the users' and other developers' machines. It shoulds satisfy your requirement. You don't need to change the resulotion. If you prefer to change the resolution, using ChangeDisplaySettings API function to implement this. Read Dynamic Screen Resolution about how to. It is a c# example. If you have any further questions, please tell us.

    Best regards,
    Riquel
    Tuesday, March 11, 2008 5:17 AM
    Moderator
  • Hi,

     

    Another good read. Even though in C#, concepts remain same

     

    http://msdn2.microsoft.com/en-us/library/ms951306.aspx

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    http://www.sqlservercurry.com
    -----

    Thursday, March 13, 2008 2:56 AM
    Moderator

All replies

  • Hi,

     

    Correct me if I am wrong, but what you intend to refer to, is the the size and placement of the controls in a form when opened in different machines having different display settings.

     

    The Anchor and Dock properties of a winform enable controls to automatically resize or reposition themselves as the form resizes.

     

    Here's some good read on the same.

     

    http://www.devx.com/dotnet/Article/6964

     

    Laying Out Windows Forms Controls with Padding, Margins, and the AutoSize Property 

     

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    http://www.sqlservercurry.com
    -----

     

    Thursday, March 06, 2008 8:30 AM
    Moderator
  • Hi,

     

    Thanks for u r reply.

    I used Anchor property but, if I install my application in the pc with 1024x768 dislay is ok. If I install in the pc which have 1280x720 the bottom page controls i.e., the controls which are at the bottom cannot be seen.

     

    Thanks,

    Narayana Ayyagari.

     

    Friday, March 07, 2008 4:22 AM
  •  

    By display settings if you mean to handle screen resolution, please know that monitor resolution can be checked using following code-

     

    My.Computer.Screen.PrimaryScreen.Bounds.Width

    My.Computer.Screen.PrimaryScreen.Bounds.Height

     

    However changing resolution of screen would require you to use API calls.

     

    Check the following thread for getting more information about it -

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=316763&SiteID=1

     

    -Ajay.

    ---------------------------------

    www.componentone.com

    ---------------------------------

    Friday, March 07, 2008 5:28 AM
  •  Narayana A programmer wrote:

    Hi,

     

    Thanks for u r reply.

    I used Anchor property but, if I install my application in the pc with 1024x768 dislay is ok. If I install in the pc which have 1280x720 the bottom page controls i.e., the controls which are at the bottom cannot be seen.

     

    Thanks,

    Narayana Ayyagari.

     

     

    Right. Anchor won't solve your problem if your form is set to be taller than the user's display settings. If you made your form 768 tall, and the user has his display set to 720 tall, there is no way for him to see the bottom controls.

     

    You can either (1) set the display settings programatically as has already been stated or (2) Set your form to the SMALLEST size that your users will use, using  Anchor so that those  with larger settings get to enjoy the larger sized form. (Use SystemInformation.Working.Area.Width and Height to set the form to fill the screen).

     

    For me, this means I would usually make my form 800x600 (or maybe a few pixels smaller) because most people have the older monitors where this display setting is standard and therefore the form would fit just right.

     

    Realize that if you enlarge the display settings using VB.Net, , this visibly shrinks the controls. They will all fit onscreen but won't be very readable.  If the monitor is a large one, they will still be big enough to be readable. But with a small monitor, the users will get made at you for causing everything to be shrunk.

     

    Anyway, you should use the  QRes utility to change resolution - i only have a C# example:

     

    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 it from 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();

    }

    }

     

    Friday, March 07, 2008 6:08 AM
  • Thanks for u r reply..

     

    yes, the code worked fine. But, have to use another utility for this right..

     

    I am using directx method. I added reference for Directx 7 for visual basic type library(DxVBLib). but,  I have some probem while i'm running the code.

    The code I used for that is :

     

    Imports DxVBLib

     

    Dim dx As New DirectX7

    Dim dd As DirectDraw7

     

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Show()

    dd = dx.DirectDrawCreate("")

    Dim Height As Integer

    Dim Width As Integer

    Dim Depth As Integer

    Height = 600 ' Change this to the correct number

    Width = 800 ' Change this to the correct number

    Depth = 16 ' Change this to the correct number

    dd.SetDisplayMode(Height, Width, Depth, 0, CONST_DDSDMFLAGS.DDSDM_DEFAULT)

    End Sub

     

    But, I have problem running this code. I'm getting exception "The method or operation is not implemented".

     

    Please let me know where I'm going wrong.

     

    Thanks,

    Narayana Ayyagari.

    Monday, March 10, 2008 2:01 AM
  • Hi Narayana,

    Based on your post, your application will run in the different resolution machine.

    As far as I know, .net supplies Automatic Scaling mechanism as a solution in this scenario. Automatic scaling enables a form and its controls, designed on one machine with a certain display resolution or system font, to be displayed appropriately on another machine with a different display resolution or system font. It assures that the form and its controls will intelligently resize to be consistent with native windows and other applications on both the users' and other developers' machines. It shoulds satisfy your requirement. You don't need to change the resulotion. If you prefer to change the resolution, using ChangeDisplaySettings API function to implement this. Read Dynamic Screen Resolution about how to. It is a c# example. If you have any further questions, please tell us.

    Best regards,
    Riquel
    Tuesday, March 11, 2008 5:17 AM
    Moderator
  • Hi Riquel,

     

    Thanks for reply..

     

    Can u tell me more indetail about Automatic Scaling mechanism and how I can implement so as to solve the resolution(display) problem..

     

    Thanks,

     

    Narayana Ayyagari.

    Wednesday, March 12, 2008 2:14 AM
  • Hi Narayana,

    I only see the introduction about Automatic Scaling from the above link(

    http://msdn2.microsoft.com/en-us/library/ms229605(VS.80).aspx). There is a section Automatic Scaling in Action to exaplain Windows Forms to use some logic to automatically scale forms and their contents. You just need to set autoscalemode property and let .net runtime to scale for you.


    Best regards,
    Riquel
    Thursday, March 13, 2008 2:51 AM
    Moderator
  • Hi,

     

    Another good read. Even though in C#, concepts remain same

     

    http://msdn2.microsoft.com/en-us/library/ms951306.aspx

     

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    http://www.sqlservercurry.com
    -----

    Thursday, March 13, 2008 2:56 AM
    Moderator