Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic adjust screen

Status
Not open for further replies.

malk

MIS
Dec 12, 2000
84
0
0
US
How do I automatically adjust the application when the resolution of the PC changes?
My app looks great at 800 X 600, but when the resolution is different the program does not adjust. I'm sure this is a simple task, I juat don't know how to do it.
I am using VB6, but I am a C programmer. Have mercy.
 
I agree with strongm.

I usually have a "minimum" screen resolution message to let the user know if the app will look OK. You could have a maximum screen resolution, but this is not an elegant solution.
 
One solution would be to set the Window property of the form to Maximum, that way no matter what the resolution the form will adjust to the screen.
Another way would be to program a resize event..which the basics can be found in the MSDN Library


zgtrman
 
>the form will adjust to the screen

Butnone of the fonts or controls will.

And yes, you can put code into the resize event - but once you start resizing controls you discover that you have to move them relative to each other as well. And then you discover that the fonts now the wrong size, so you have to start mucking about with those. As I said, it's a pain.
 
Ok I understand .. here is some code that might get you started. I have a whole demo program that I can give you but I am not allowed to post my e mail address in here..you would have to request it through this forum.

Put this code into a Module and then make the call to the module. It will resize everything on the form except the font size. But I think you can insert a routine to do that as well
<==========Start Code========>
Option Explicit

Public Sub ResizeControls(frm As Form, oldWidth As Integer, _
oldHeight As Integer)
'Resize and readjust positions of all controls on the form

'Don't try to adjust minimized form.
If oldWidth < 1 Or oldHeight < 1 Then Exit Sub

Dim ratioW As Single, ratioH As Single
ratioW = frm.Width / oldWidth
ratioH = frm.Height / oldHeight

On Error Resume Next
Dim ctrl As Control
For Each ctrl In frm.Controls
With ctrl
.Width = .Width * ratioW
.Left = .Left * ratioW
.Height = .Height * ratioH
.Top = .Top * ratioH
End With
Next ctrl

oldWidth = frm.Width
oldHeight = frm.Height

End Sub
<=============End Code============>

Hope this puts a little light on your project
 
you also need to put this into your forms

************Start Form Code***************
Option Explicit
Private mintSaveWidth As Integer
Private mintSaveHeight As Integer

'additional vars for min and max
Dim intMinHeight As Integer, intMinWidth As Integer



Private Sub Form_Activate()
'Save Last height and width
mintSaveWidth = Me.Width
mintSaveHeight = Me.Height
End Sub

Private Sub Form_Load()
'Get the form min height and width
'Assume the programmer correctly sized the form initially
intMinHeight = Me.Height
intMinWidth = Me.Width
End Sub

Private Sub Form_Resize()
If (Me.Height >= intMinHeight) And (Me.Width >= intMinWidth) Then
ResizeControls Me, mintSaveWidth, mintSaveHeight
Else
'Force the form back to its last size
Me.Width = mintSaveWidth
Me.Height = mintSaveHeight
End If

End Sub
***************End Form Code*********************


zgtrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top