Solved

VB6 Resize buttons, forms etc

Posted on 2010-09-17
3
421 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now