Screen/Font Res Changes

I am trying to get an application to change the form/ control and font sizes, according to the screen res of the host machine.

I can get the current screen resolution and color depth, but I am stuck when it comes to changing the sizes and postions of the controls, and more so changing the size of the font.

Any help would be appreciated...
clienttechAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
watyConnect With a Mentor Commented:
I use this class in some of my applications which needs this kind of support :

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "class_Elastic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'****************************************************************
' Name: class_Elastic
' Description:This class can change size and location of controls
'  on your form
' 1. Resize form
' 2. Change screen resolution

' By: Mikhail Shmukler
'
' Inputs:None
' Returns:None
' Assumes:1. Add Elastic.cls
'2. Add declaration 'Private El as New class_Elastic'
'3. Insert string like 'El.init Me' (formload event)
'4. Insert string like 'El.FormResize Me' (Resize event)
'5. Press 'F5' and resize form ....
' Side Effects:None
'
'****************************************************************

Option Explicit
Private nFormHeight      As Integer
Private nFormWidth       As Integer
Private nNumOfControls   As Integer
Private nTop()           As Integer
Private nLeft()          As Integer
Private nHeight()        As Integer
Private nWidth()         As Integer
Private nFontSize()      As Integer
Private nRightMargin()   As Integer
Private bFirstTime       As Boolean

Sub Init(frm As Form, Optional nWindState As Variant)
   
   Dim I          As Integer
   Dim bWinMax    As Boolean
   
   bWinMax = Not IsMissing(nWindState)
   
   nFormHeight = frm.Height
   nFormWidth = frm.Width
   nNumOfControls = frm.Controls.Count - 1
   bFirstTime = True
   ReDim nTop(nNumOfControls)
   ReDim nLeft(nNumOfControls)
   ReDim nHeight(nNumOfControls)
   ReDim nWidth(nNumOfControls)
   ReDim nFontSize(nNumOfControls)
   
   ReDim nRightMargin(nNumOfControls)
   On Error Resume Next
   For I = 0 To nNumOfControls
      If TypeOf frm.Controls(I) Is Line Then
         nTop(I) = frm.Controls(I).Y1
         nLeft(I) = frm.Controls(I).X1
         nHeight(I) = frm.Controls(I).Y2
         nWidth(I) = frm.Controls(I).X2
      Else
         nTop(I) = frm.Controls(I).Top
         nLeft(I) = frm.Controls(I).Left
         nHeight(I) = frm.Controls(I).Height
         nWidth(I) = frm.Controls(I).Width
         nFontSize(I) = frm.FontSize
         nRightMargin(I) = frm.Controls(I).RightMargin
      End If
   Next
   
   If bWinMax Or frm.WindowState = 2 Then ' maxim
      frm.Height = Screen.Height
      frm.Width = Screen.Width
   Else
      frm.Height = frm.Height * Screen.Height / 7290
      frm.Width = frm.Width * Screen.Width / 9690
   End If
   
   bFirstTime = True
   
End Sub

Sub FormResize(frm As Form)
   
   Dim I             As Integer
   Dim nCaptionSize  As Integer
   Dim dRatioX       As Double
   Dim dRatioY       As Double
   Dim nSaveRedraw   As Long
   
   On Error Resume Next
   nSaveRedraw = frm.AutoRedraw
   
   frm.AutoRedraw = True
   
   If bFirstTime Then
      bFirstTime = False
      Exit Sub
   End If
   
   If frm.Height < nFormHeight / 2 Then frm.Height = nFormHeight / 2
   
   If frm.Width < nFormWidth / 2 Then frm.Width = nFormWidth / 2
   nCaptionSize = 400
   dRatioY = 1# * (nFormHeight - nCaptionSize) / (frm.Height - nCaptionSize)
   dRatioX = 1# * nFormWidth / frm.Width
   On Error Resume Next ' for comboboxes, timeres and other nonsizible controls
   
   For I = 0 To nNumOfControls
      If TypeOf frm.Controls(I) Is Line Then
         frm.Controls(I).Y1 = Int(nTop(I) / dRatioY)
         frm.Controls(I).X1 = Int(nLeft(I) / dRatioX)
         frm.Controls(I).Y2 = Int(nHeight(I) / dRatioY)
         frm.Controls(I).X2 = Int(nWidth(I) / dRatioX)
      Else
         frm.Controls(I).Top = Int(nTop(I) / dRatioY)
         frm.Controls(I).Left = Int(nLeft(I) / dRatioX)
         frm.Controls(I).Height = Int(nHeight(I) / dRatioY)
         frm.Controls(I).Width = Int(nWidth(I) / dRatioX)
         frm.Controls(I).FontSize = Int(nFontSize(I) / dRatioX) + Int(nFontSize(I) / dRatioX) Mod 2
         frm.Controls(I).RightMargin = Int(nRightMargin(I) / dRatioY)
      End If
   Next
   
   frm.AutoRedraw = nSaveRedraw
   
End Sub
0
 
mcriderCommented:
Are you talking about "Large Font" vs. "Small Font"?
0
 
mcriderCommented:
If you are, check out this microsoft KB Article:

HOWTO: Know if Large/Small Font Is in Use Under Win95/98/NT
http://support.microsoft.com/support/kb/articles/Q152/1/36.asp 
 

Cheers!

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
setiawanCommented:
Hi clienttech,

I think screen resolution is a very classic matter for vb programmer's
there is so many question around this problem, particularly in EE.
but the answer is no.

actually there is 2 solution :
- change your client screen resolution and change it back after your program finished, but the problem, If the client monitor doesn't support for your screen resolution, beside People hate if you change their screen resolution.

- like you said, change all your control depend on screen resolution, but It also have problem, If you use so many control.

  danny
0
 
Vin32Commented:
you could  use scaleheight and scalewidth propertties for you controls.
0
 
clienttechAuthor Commented:
I need my application to resize itself depending on the screen resolution, taking into account the font size as well.

I cannot change the client screen res, since my app will be working in conjuntion with several others. Besides, I think the users might complain!

Vin32:
Could you explain the use of scaleheight and scalewidth and how they might be of help to me.

Thanks to all for the quick response...
0
 
clienttechAuthor Commented:
Waty: My thanks - Excellent!
0
All Courses

From novice to tech pro — start learning today.