Link to home
Start Free TrialLog in
Avatar of pmac38CDS
pmac38CDS

asked on

Resize controls and screen resolution independence without 3rd party controls....

I am looking for some help in figuring out the best way to resize our applications. Right now we use a 3rd party resize tool and would like to get away from it if possible.  After talking to Microsoft the other day about a unrelated problem he said that if was are using VS2005 that we dont need a 3rd party resize tool.  I'm attaching a little sample project with one form.  If you open it at 1024x768 and run the app you will notice that everything on the form shows up fine.  If you then drop your resolution down to 800x600 you will notice that it only shows about half of the form because the form didnt resize nor did the controls on the form resize.  Can someone show me in basic.net how to resize the form using docking and anchoring and autoscaling(all suggested by Microsoft) so that all the controls appear on the form just like they do in 1024 res.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi pmac38CDS;

This is what Microsoft was talking about in this article. Talks about original support, VS 2002 & VS 2003 and current support VS 2005.  You also did not post a link to the project.

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

Fernando
Avatar of pmac38CDS
pmac38CDS

ASKER

I am trying to post the link now.  I always forget where it is that I have to go to upload a sample.
Hi pmac38CDS;

This is the EE-Stuff web site to post uploads. Username and password is the same as the main EE web site.

http://www.ee-stuff.com/login.php

Fernando
Hi pmac38CDS;

I have not been able to make it work correctly. The following will cause you a problem. The form height is set to 721 pixels and the form can not be made bigger then the resolution of the screen. At 1024 x 768 it has a little space on the top and bottom of the form but when set to 800 x 600 the system automatically sets the height of the form at 600 pixels and does not display the bottom row of buttons. Even if you did something like the following in form load:

        If Screen.PrimaryScreen.Bounds.Width < 1024 Then
            Me.Scale(New SizeF(0.95F, 0.95F))
        End If

The form has already been resized before it gets to the form load and therefore shows a scaled down version with still no buttons on the bottom in view. The only way I have been able to get the whole form to be viewable is by doing the following:

        If Screen.PrimaryScreen.Bounds.Width < 1024 Then
            Me.AutoScroll = True
        End If

Which places scroll bars as needed and allowing you to scroll the row of buttons to come into view, This will take the whole screen. To make the form have some space around it at that resolution you can do the following in the form load.

        If Screen.PrimaryScreen.Bounds.Width < 1024 Then
            Me.AutoScroll = True
            Me.Scale(New SizeF(0.95F, 0.95F))
        End If

The Me.Scale will scale down the whole form to 95% of the original size when ran in a resolution lower then 1024 x 768.

Fernando
So none of the code resizes each control?  Not only do we want the form itself to look the same we also want each control to be resized to fit that resolution.  I played around with some of your code and no matter which resolution I was at, the buttons for instance seemed to stay the same size and never adjusted to which resolution it was in.  Right now we use Larcom and Youngs 3rd party resizer.  What we do is just add it to each form and then it resizes every control on that form to fit whatever resolution the client using our app is at.  The Microsoft guy said this could be accomplished also.  Is that right or am I missing something?
The following is from the Microsoft article:

An analogous situation occurs when an application is designed for a certain display resolution. The most common display resolution is 96 dots per inch (DPI), but higher resolution displays supporting 120, 133, 170, and above are becoming more common. Without adjustment, an application, especially a graphics-based one, designed for one resolution will appear either too large or too small when run at another resolution.

Automatic scaling seeks to ameliorate these problems by automatically resizing the form and its child controls according to the relative font size or display resolution. The Windows operating system supports automatic scaling of dialog boxes using a relative unit of measurement called dialog units. A dialog unit is based on the system font and its relationship to pixels can be determined though the Win32 SDK function GetDialogBaseUnits. When a user changes the theme used by Windows, all dialog boxes are automatically adjusted accordingly.

The above is talking about DPI as the resolution. Which means that a monitor set to 1024 x 768 with a DPI of 96 will display the same, without scaling, on a monitor of resolution 800 x 600 at a DPI of 96. What I believe would be the case is that if the program was developed on a system with a screen resolution of 1024 x 768 at a DPI setting of 133 and that program was run on a system with a screen resolution of 800 x 600 with a DPI setting of 96 then the form and all of its child control would scale. Which is not what you are looking for.

Fernando
So you are saying bascially that I have to stick with my 3rd party resizer to handle this for me?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial