Click to See Complete Forum and Search --> : Resolution


Harini
June 25th, 2001, 03:45 PM
Hello,

How can we make an application Resolution independent and font independent?


Thanks
Harini

Kdev
June 25th, 2001, 04:15 PM
You'll need to scale all your components using the screen.width and screen.height properties.

Form1.width = screen.width
Form1.height = screen.height

I haven't done a lot with scaleing an app but you would probably want to set up a scaleing based on the screen.width and screen.height properties. For example if you design your app to run best at 800x600 then you would probably do something like this:

Form1.width = ((screen.width/screen.twipsperpixelx) / 800) * Form1.width

Form1.height = ((screen.height/screen.twipsperpixely) / 600) * Form1.height

In this manner you are scaleling whatever you designed by the current resolution to maintain proportion.

You would also need to adjust left and top properties I would imagine in a similar fashion.

-K

shree
June 26th, 2001, 08:27 AM
The following is a simple code that you can use to make a form designed in 800x600 mode uniform over all resolutions.


private Sub Form_Load()
on error resume next
Dim CtrlVar as Control
Xratio = Screen.Width / (Screen.TwipsPerPixelX * 800)
Yratio = Screen.Height / (Screen.TwipsPerPixelY * 600)
for Each CtrlVar In FrmVar.Controls
CtrlVar.Left = CtrlVar.Left * Xratio
CtrlVar.Top = CtrlVar.Top * Yratio
CtrlVar.Width = CtrlVar.Width * Xratio
CtrlVar.Height = CtrlVar.Height * Yratio
CtrlVar.Font.Size = CtrlVar.Font.Size * XRatio
next CtrlVar
End Sub

Harini
June 26th, 2001, 10:42 AM
Hello Shree,

Thanks for ur prompt reply.

We have tried the method suggested by you. Somehow we still have problems. Could you please tell us where we are going wrong.
I have one Main MDI form and four child forms.

Here is the code that I Placed in the form_load.


xratio = Screen.Width / (Screen.TwipsPerPixelX * 1024)
yratio = Screen.Height / (Screen.TwipsPerPixelY * 768)
me.Left = 3766 * xratio
me.Top = 1130 * yratio
me.Width = 6250 * xratio
me.Height = 3800 * yratio




With the above code the form appears on the main MAin MDI form at the required position with required size. However if I change the resolution to 800 x 600 then the form size gets distrubed. Am I doing some thing wrong.


Please suggest accordingly

Thanks
Harini

shree
June 26th, 2001, 11:09 AM
If you step through your code, you might see that Screen.Width is not being returned correctly. I don't think that this problem will persist in the executable. You'll see that the program performs as expected if you quit and restart VB after changing the screen resolution. Not all programs perform predictably after changing the display properties.

Harini
June 28th, 2001, 10:08 AM
Hello Shree,

The advice that you gave is really working out well.
Now that the form and the controls are resized as per the systems resolution, the following are the problems that I am facing now.

1. When I debug the code, it shows that the frames in form are moved, by changin the left, top, height and width. But this is not shown when the application is run.
2. The font size is not changed even in the debug mode, nor is it shown when the application is run.

Please help me out with the above two issues.


Thanks
Harini

shree
June 28th, 2001, 11:23 AM
1. I'm not sure
2. You must be using the MS Sans Serif font (the default) and it is not a truetype font, so it cannot have a size less than 8. Use some other font, such as Arial.