Solved

Resizing A Form

Posted on 1998-08-05
9
255 Views
Last Modified: 2010-05-03
How to automatically resize the forms of a VB project when the size of the monitor changes?

Amanda
0
Comment
Question by:Amanda080598
9 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1467915
Do you mean when the resoltion changes?

When your form loads, check the resolution of the screen with the properties:
  Screen.Width and Screen.Height.
Make your forms a percentage of that value.

This code will size a form to 1/4 of the screen no matter what the resolution:
Private Sub_Load()
  Form1.Height = Screen.Height / 2
  Form1.Width = Screen.Width / 2
End Sub
0
 

Author Comment

by:Amanda080598
ID: 1467916
I need to center all the controls, text, and labels within the form for each resolution.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467917
Again, it's a percentage of the screen dimensions.

OK, here's an idea.  Use a picturebox on your form as a container for all the controls on your form.  Place all the controls, text, and labels which were on the form onto the picturebox (you can use cut & paste wich will keep the controls position relative to each other).  Placing your controls on the picture box will allow you to move all the controls at one time rather than individually.  Finally, after you resize your form in my above example, use this code:
  Picture1.Move (Me.Width - Picture1.Width) / 2, (Me.Height - Picture1.Height) / 2

You might put this code in the form's resize event so that, whenever the form is resized, the controls stay centered.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:Amanda080598
ID: 1467918
Without programming each control individually - I need to be able to use the application on a 14 inch and a 17 inch screen.  The controls should not change positions with either screen size.  Using the Private Sub_Load()
  Form1.Height = Screen.Height / 2
  Form1.Width = Screen.Width / 2
End Sub
does not solve the problem.

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467919
Unfortunately, there is no way (that I know of) to tell where, in inches, a position on the screen is.

Within a form this is possible if you change the ScaleMode property to inches.  However, there is no ScaleMode property for the screen object.

You should reject my answer in case there is another expert who does know a way.

Good luck.
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1467920
A control called the VS Flex control from Videosoft will automatically take care of proportionally resizing all your controls on the form when the control is resized.  This process also retains all relative spacing and positioning as well.  You can download a working demo from the Videosoft site on the web.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1467921
cymbolic:
The control you refer to is not VSFlex (Videosoft's grid control), it's VSOCX (or sold alone as ElasticLight).
I am familiar with this control and it will resize based on resolution, however I don't think it will resize based on the physical size of the monitor which is what Amanda wants.
0
 

Accepted Solution

by:
manuelfrancis earned 50 total points
ID: 1467922
the question is not very much clear...
because the first question is itself is not correct (How to automatically resize the forms of a VB project when the size of the monitor changes? )
nothing will change if you changes the monitor from  14 to 17 inch. the screen resolution is the thing that changes the behavior of the controlls. you can use the 640 / 480 resolution at both monitors there will not be any change in the position at all.

Form_Load()
Dim I

      For I = 0 To me.Controls.Count - 1
            If TypeOf me.Controls(I) Is Not Menu Then
                  me.Controls(I).left=%*Screen
            End If
      Next I

End if

You can get the controlls in a form by the above code.
if you add this code in the form load event of the Form the from there you can possion the any contoll referrance to the screen.

Hope you can modify this code....
or else i can get you a detailed answer...
0
 

Author Comment

by:Amanda080598
ID: 1467923
Hey, who graded this question.  I know I didn't.

Amanda
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 55
Run code from text file in vb 1 64
MS Date Picker 64 bit 32 bit issue 12 54
How to set the sa password in a vb6 code for sql connection 9 54
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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