Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB6 Resize buttons, forms etc

Posted on 2010-09-17
3
Medium Priority
?
445 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

972 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