Solved

VB6 Resize buttons, forms etc

Posted on 2010-09-17
3
428 Views
Last Modified: 2013-12-25
Basically I have a VB6 program that when run maximizes form1 to fit the screen, the problem I have is that this program was written for a resolution of 1024x768 so when it is run on a lower resoloution not everything fits in (buttons etc) and on a higher resolution has big gaps round the edges.

I still want the program to be maximised when opened but I want all the buttons, textboxes etc to be resized so on a lower resolution become smaller and on a higher become bigger so they fill the screen exactly the same as with the current 1024x768 resolution.
0
Comment
Question by:souldigital
3 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33701456
What you want is a percentage. Set the form to 1024x768. We're assuming here you have a button and a textbox.Button has 10 width, 3 height. Textbox has 20 width, 3 height.
Now, what you want is to set the ratio when the form opens.

scrHeight=Screen.Height
scrWidth=Screen.Width
Button.Height=3*scrHeight/1024
Button.Width=10*scrWidth/768
Textbox.Height=3*scrHeight/1024
Textbox.Width=20*scrWidth/768

Something like this, anyway. You might have to also use something similar to calculate Left and Top properties.
0
 
LVL 14

Accepted Solution

by:
VBClassicGuy earned 500 total points
ID: 33701475
0
 
LVL 5

Expert Comment

by:BrianVSoft
ID: 33707273
We use code similar to the code sample linked by VBClassicGuy
We had to add several extra bits in the FormResize event.
1. If Me.WindowState = 1 Then Exit Sub  '(This prevents an error when Minimizing.)
2. If you have lots of controls, that example will be too slow because it will try to resize everything a hundred times a second (with every pixel of mouse movement) We had to include an Exit Sub if the NEW Width+Height was within a few percent of OLD Width+Height. (a simple line of math) This restricted resizing to only occur once every tenth inch or so.
3. The example also attempts to center the form on the screen - most users won't want that- those few lines can be removed.
4. You should also Exit Sub if the Width or Height is now less than a preset minimum size.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

839 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