Adjusting for Screen Resolutions 
Author Message
 Adjusting for Screen Resolutions

Does anyone no an easy way to adjust for different screen resolutions.
I tried looping through the Form.Controls collection on the Form_load
event of every form (using screen.TwipsPerPixelX to come up with a
scaling factor to adjust each objects left,right,top, etc. properties),
but I haven't quite been able to get it to work.  Any help would be
greatly appreciated.

Thanks,
David



Sat, 18 Apr 1998 03:00:00 GMT  
 Adjusting for Screen Resolutions

Quote:

>Does anyone no an easy way to adjust for different screen resolutions.
>I tried looping through the Form.Controls collection on the Form_load
>event of every form (using screen.TwipsPerPixelX to come up with a
>scaling factor to adjust each objects left,right,top, etc. properties),
>but I haven't quite been able to get it to work.  Any help would be
>greatly appreciated.

Try this code out. I have not used it for awhile so you may have to
debug it yourself:

Sub SetDeviceIndForm (thisform As Form)
    'changes position and size of controls and forms to create a device-independent
form
    On Error GoTo set_ind_form_err
    Dim designX%, designY%, Xfactor As Single, Yfactor As Single, x As Integer, flag
    designX% = 9600
    designY% = 7200
    Xfactor = Screen.Width / designX%
    Yfactor = Screen.Height / designY%

    If Xfactor = 1 And Yfactor = 1 Then
        thisform.Top = (Screen.Height / 2) - (thisform.Height / 2)
        thisform.Left = (Screen.Width / 2) - (thisform.Width / 2)
        Exit Sub
    Else
        thisform.Move thisform.Left * Xfactor, thisform.Top * Yfactor,
thisform.Width * Xfactor, thisform.Height * Yfactor
        thisform.Top = (Screen.Height / 2) - (thisform.Height / 2)
        thisform.Left = (Screen.Width / 2) - (thisform.Width / 2)
    End If

    For x = 0 To thisform.Controls.Count - 1
        flag = 0
        If TypeOf thisform.Controls(x) Is ComboBox Then flag = 3
        If TypeOf thisform.Controls(x) Is CommandButton Then flag = 2
        If TypeOf thisform.Controls(x) Is Frame Then flag = 2
        'If TypeOf thisform.Controls(x) Is Gauge Then flag = 1
        'If TypeOf thisform.Controls(x) Is Grid Then flag = 2
        If TypeOf thisform.Controls(x) Is Label Then flag = 2
        If TypeOf thisform.Controls(x) Is Line Then flag = 4
        'If TypeOf thisform.Controls(x) Is MaskEdBox Then flag = 2
        If TypeOf thisform.Controls(x) Is Shape Then flag = 1
        'If TypeOf thisform.Controls(x) Is SSCheck Then flag = 2
        'If TypeOf thisform.Controls(x) Is SSCommand Then flag = 2
        'If TypeOf thisform.Controls(x) Is SSFrame Then flag = 2
        'If TypeOf thisform.Controls(x) Is SSOption Then flag = 2
        'If TypeOf thisform.Controls(x) Is SSPanel Then flag = 2
        If TypeOf thisform.Controls(x) Is TextBox Then flag = 2

        'If TypeOf thisform.Controls(x) Is DB_ListClass Then flag = 2
        If TypeOf thisform.Controls(x) Is DirListBox Then flag = 2
        If TypeOf thisform.Controls(x) Is DriveListBox Then flag = 3
        If TypeOf thisform.Controls(x) Is FileListBox Then flag = 2
        If TypeOf thisform.Controls(x) Is ListBox Then flag = 2

        If flag < 3 And flag > 0 Then
            thisform.Controls(x).Move thisform.Controls(x).Left * Xfactor,
thisform.Controls(x).Top * Yfactor, thisform.Controls(x).Width * Xfactor,
thisform.Controls(x).Height * Yfactor
        End If
        If flag < 3 And flag > 1 Then
            thisform.Controls(x).FontSize = thisform.Controls(x).FontSize * Xfactor
        End If
        If flag = 3 Then
            If thisform.Controls(x).Style <> 1 Then
                thisform.Controls(x).Move thisform.Controls(x).Left * Xfactor,
thisform.Controls(x).Top * Yfactor, thisform.Controls(x).Width * Xfactor
                thisform.Controls(x).FontSize = thisform.Controls(x).FontSize *
Xfactor
                thisform.Controls(x).Refresh
            End If
        End If
        If flag = 4 Then
            thisform.Controls(x).X1 = thisform.Controls(x).X1 * Xfactor
            thisform.Controls(x).X2 = thisform.Controls(x).X2 * Xfactor
            thisform.Controls(x).Y1 = thisform.Controls(x).Y1 * Yfactor
            thisform.Controls(x).Y2 = thisform.Controls(x).Y2 * Yfactor
        End If
    Next x
    Exit Sub
set_ind_form_err:
    If Err = 422 Then Resume Next
    MsgBox "Error: " + Str$(Err) + " - " + Error$(Err)
    Resume Next
End Sub

-----------------------------------------------------------
  Want a program to keep track of all those movie/videos
         around the house? Try this out for use.
            (Look for MUSICLOG comming soon)
ftp://ftp.cica.indiana.edu/pub/pc/win3/uploads/movielog.txt
ftp://ftp.cica.indiana.edu/pub/pc/win3/uploads/movielog.exe
-----------------------------------------------------------



Sun, 19 Apr 1998 03:00:00 GMT  
 Adjusting for Screen Resolutions

Quote:

> Does anyone no an easy way to adjust for different screen resolutions.
> I tried looping through the Form.Controls collection on the Form_load
> event of every form (using screen.TwipsPerPixelX to come up with a
> scaling factor to adjust each objects left,right,top, etc. properties),
> but I haven't quite been able to get it to work.  Any help would be
> greatly appreciated.
> Thanks,
> David

A thought about this auto-scaling business: I don't know about
anyone else, but I'm using 1280x1024 mode in order to see more
windows, not so the same old windows can simply soak up more
pixels. Anyway, in my own code, I usually design for 640x480 (for
our notebook users) and let the user resize or maximize the
window if s/he wants it to take up more screen space. I usually
then save the window's size and position in the INI file in the
Close event and read it in the Load event. The resize code
usually ends up being messy, because I want some controls (like
textboxes) to resize in one dimension but not the other, and
others (such as multiline boxes or grids) to resize in both, and
still others to simply reposition themselves. I haven't found a
perfect generic solution yet.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sun, 19 Apr 1998 03:00:00 GMT  
 Adjusting for Screen Resolutions

Quote:
>I haven't found a perfect generic solution yet.

I found the perfect solution by asking here a couple of weeks ago.  It
is called VSVBX.  You throw down an elastic background then build all
controls on top of that.  You then use a simple scale routine and the
elastic automatically stretches or shrinks all controls for you.

Bruce
Bruce D. Wedding                        Have Compiler, Will Travel!
Software Demi God                      
Katy, TX, USA #1



Mon, 20 Apr 1998 03:00:00 GMT  
 Adjusting for Screen Resolutions

Quote:


>>I haven't found a perfect generic solution yet.

>I found the perfect solution by asking here a couple of weeks ago.  It
>is called VSVBX.  You throw down an elastic background then build all
>controls on top of that.  You then use a simple scale routine and the
>elastic automatically stretches or shrinks all controls for you.

My thoughts on this:

VSVBX may not perfectly size fonts and such,  plus it costs money,  and
I'm as cheap as they get.  :-)

I tried using VB to iteratively go through each control on a form to resize
it to the given screen resolution,  but I find that it's very slow,  so
I've abandoned that idea.

I've decided that I either *tell* my user that it only works at a certain
resolution,  or I make copies of the program for other resolutions (with
a lot of annoying form redesigning by hand).  Sure,  it's not a generic,
universal solution,  but then,  my users are specific people usually,
not the general public.  If it was the general public that I was targeting,
then I would consider using VSVBX or something.

Ciao for now,
  - Steve Weigand



Mon, 27 Apr 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adjust to screen resolution

2. Prog. App. to adjust to screen resolution

3. problem adjusting screen resolution

4. Screen resolution auto adjusting?

5. Adjusting VB for different screen resolutions

6. Adjust forms to users' screen resolution

7. VB 3.0 help: adjusting control size to screen resolution

8. Adjusting forms / controls for different screen resolutions.

9. How to adjust control sizes and dimensions to suit different screen resolutions

10. Adjusting controls to different screen-resolutions

11. Adjusting controls to different screen-resolutions

12. API-call for getting/adjusting sreen resolution

 

 
Powered by phpBB® Forum Software