?
Solved

Changing Resolution

Posted on 2003-03-04
10
Medium Priority
?
314 Views
Last Modified: 2010-05-18
i have programmed an application in a 1024x768 resolution, but when i install the program in other pc with other resolution i get lot of troubles!!

i have heard there is a way to automate this process??
0
Comment
Question by:athe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 11

Expert Comment

by:supunr
ID: 8068296
I am not sure what you mean by problems or what you to automate.  I believe you have not written the code to do the form resize.  If you have any resizable forms you have to add Form_Resize event.  Follwoing is a sample code for form_Resize.


Prive Sub Form_Resize()
     On Error Resume Next ' Non-Critical Errors
     if (WindowState = vbMinimized) then Exit Sub

     ' Set window limits
     if (Height < 3000) then Height = 3000     ' twips
     if (Width < 3000) then Width = 3000   ' twips

     ' Move the grid to fit the screen - bottom layer for button
     Grid1.Move 50, 50, ScaleWidth, ScaleHeight - Button1.Height - 200
     ' Center the button
     Button1.Move (ScaleWidth - Button1.Width) / 2, ScaleHeight - Button1.Height
End Sub

Good Luck!
0
 
LVL 3

Expert Comment

by:DocM
ID: 8068476
' Microsoft Knowledgebase Article ID: Q182070
' 1) Change the video resolution to 800 x 600.
' 2) Start a new project in Visual Basic. Form1 is created by default.
' 3) Add a Label, a CommandButton, and any other types of controls you would like to test.

'Copy the following code into the Form's module:
Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer


Private Sub Form_Load()
Dim ScaleFactorX As Single, ScaleFactorY As Single  ' Scaling factors
' Size of Form in Pixels at design resolution
DesignX = 800
DesignY = 600
RePosForm = True   ' Flag for positioning Form
DoResize = False   ' Flag for Resize Event
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips  ' X Pixel Resolution

' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
ScaleMode = 1  ' twips
'Exit Sub  ' uncomment to see how Form1 looks without resizing
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
"  by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub

Private Sub Form_Resize()
Dim ScaleFactorX As Single, ScaleFactorY As Single

If Not DoResize Then  ' To avoid infinite loop
   DoResize = True
   Exit Sub
End If

RePosForm = False
ScaleFactorX = Me.Width / MyForm.Width   ' How much change?
ScaleFactorY = Me.Height / MyForm.Height
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub

Private Sub Command1_Click()
Dim ScaleFactorX As Single, ScaleFactorY As Single

DesignX = Xpixels
DesignY = Ypixels
RePosForm = True
DoResize = False
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips  ' X Pixel Resolution

' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
"  by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub


' 4) Add a Module from the Project menu and paste in the following code:

Public Xtwips As Integer, Ytwips As Integer
Public Xpixels As Integer, Ypixels As Integer


Type FRMSIZE
   Height As Long
   Width As Long
End Type

Public RePosForm As Boolean
Public DoResize As Boolean

Sub Resize_For_Resolution(ByVal SFX As Single, _
ByVal SFY As Single, MyForm As Form)
Dim I As Integer
Dim SFFont As Single

SFFont = (SFX + SFY) / 2  ' average scale
' Size the Controls for the new resolution
On Error Resume Next  ' for read-only or nonexistent properties
With MyForm
  For I = 0 To .Count - 1
   If TypeOf .Controls(I) Is ComboBox Then   ' cannot change Height
     .Controls(I).Left = .Controls(I).Left * SFX
     .Controls(I).Top = .Controls(I).Top * SFY
     .Controls(I).Width = .Controls(I).Width * SFX
   Else
     .Controls(I).Move .Controls(I).Left * SFX, _
      .Controls(I).Top * SFY, _
      .Controls(I).Width * SFX, _
      .Controls(I).Height * SFY
   End If
     .Controls(I).FontSize = .Controls(I).FontSize * SFFont
  Next I
  If RePosForm Then
    ' Now size the Form
    .Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
  End If
End With
End Sub
0
 

Author Comment

by:athe
ID: 8068583
but i want to resize EVERY form on the project... do i have to do all this with everyform??

i think i should not understand you.... :(
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:DocM
ID: 8068727
It is only a few lines of codes to copy and paste.
0
 

Author Comment

by:athe
ID: 8068803
i have seen it works in the test form i have created, but when i have to include that code on mine.... do i have to include for each control i want to resize?? i think it could be too hard.... for each commandbutton, each label, each dbgrid, each frame.... too too hard.... i think im not understanding you yet
0
 
LVL 3

Expert Comment

by:DocM
ID: 8070203
'This code only once in a Module
Public Xtwips As Integer, Ytwips As Integer
Public Xpixels As Integer, Ypixels As Integer


Type FRMSIZE
  Height As Long
  Width As Long
End Type

Public RePosForm As Boolean
Public DoResize As Boolean

Sub Resize_For_Resolution(ByVal SFX As Single, _
ByVal SFY As Single, MyForm As Form)
Dim I As Integer
Dim SFFont As Single

SFFont = (SFX + SFY) / 2  ' average scale
' Size the Controls for the new resolution
On Error Resume Next  ' for read-only or nonexistent properties
With MyForm
 For I = 0 To .Count - 1
  If TypeOf .Controls(I) Is ComboBox Then   ' cannot change Height
    .Controls(I).Left = .Controls(I).Left * SFX
    .Controls(I).Top = .Controls(I).Top * SFY
    .Controls(I).Width = .Controls(I).Width * SFX
  Else
    .Controls(I).Move .Controls(I).Left * SFX, _
     .Controls(I).Top * SFY, _
     .Controls(I).Width * SFX, _
     .Controls(I).Height * SFY
  End If
    ' Better not change fontsize
    '.Controls(I).FontSize = .Controls(I).FontSize * SFFont
 Next I
 If RePosForm Then
   ' Now size the Form
      .Move .Left, .Top, .Width * SFX, .Height * SFY
 End If
End With
End Sub

'--------------------------

'This code only once in each form
Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer


Private Sub Form_Load()

Dim ScaleFactorX As Single, ScaleFactorY As Single  ' Scaling factors
' Size of Form in Pixels at design resolution
DesignX = 800
DesignY = 600

RePosForm = True   ' Flag for positioning Form
DoResize = False   ' Flag for Resize Event
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips  ' X Pixel Resolution

' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
ScaleMode = 1  ' twips
'Exit Sub  ' uncomment to see how Form1 looks without resizing
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
"  by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
 
End Sub

Private Sub Form_Resize()

Dim ScaleFactorX As Single, ScaleFactorY As Single

If Not DoResize Then  ' To avoid infinite loop
  DoResize = True
  Exit Sub
End If

RePosForm = False
ScaleFactorX = Me.Width / MyForm.Width   ' How much change?
ScaleFactorY = Me.Height / MyForm.Height
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width

End Sub

'----------------------------
0
 

Author Comment

by:athe
ID: 8070741
i have copied first part in a module and second one once in a form but it doesm't work!! :( what have i done wrong?
0
 
LVL 3

Expert Comment

by:DocM
ID: 8074401
It works fine here. Start the program and resize the form to see that the controls are resized also.
Change the resolution and restart the program and see the form and the controls being resized.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9046870
Hi athe,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

athe, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9151046
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question