Solved

Resize forms automatically when display resolutions changes

Posted on 2000-04-12
19
180 Views
Last Modified: 2010-08-05
How can I make my forms in my application in VB change automatically and correspondingly when the display resolution changes? example : I did my application development in 1024X 768. When I port my program into another workstation, whose display resolution is 640X480, the forms become too big. How to correct these problems?
Thank you.
0
Comment
Question by:sunburnt
  • 9
  • 4
  • 2
  • +4
19 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2710397
In my Form_Load event, I always first intitialize my Form sizes by using the screen coordinates. Try putting this into your Form_Load event..

Private Sub Form1_Load ()

'  From1.Move(Left, Top, Width, Height)
   Form1.Move _
      Screen.Width * .1, _
      Screen.Height * .1, _
      Screen.Width * .8, _
      Screen.Height * .8

Exit Sub

In my Form_Resize event I then size all my controls in relationship to the Form's scale dimensions.

Private Sub Form1_Resize ()

   If WindowState = vbMinimized _
   Then
      Exit Sub
   End If

'  Label On Top
   Label1.Move _
      ScaleLeft * 0, _
      ScaleTop * 0, _
      ScaleWidth * 1, _
      Label1.Height

'  Command On Bottom
   Command1.Move _
      ScaleLeft * 0, _
      ScaleHeight - Command1.Height, _
      ScaleWidth * 1, _
      Command1.Height

' Text in Between

'  Command On Bottom
   Text1.Move _
      ScaleLeft * 0, _
      ScaleTop + Label1.Height, _
      ScaleWidth * 1, _
      ScaleHeight - Command1.Height - Label1.Height

Exit Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2710437
if youre lazy with the coding you can find free "resize" controls all over the place.  cnet.com, planetsourcecode.com, etc.  i personally prefer the code to limit the amount of controls i throw on a form but if this isnt going to be distributed anywhere you may look into getting you one of these controls to save you some time in the future having to write it all out.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2710465
Azra:
I have looked at all those resizing controls.. and like you.. I personally prefer to do my own sizing. Its a little bit of a pain in the neck.. but then again.. I don't end up with 4inch high command buttons.. and I always optimize for every inch of desktop space that I get. The more I work with it, the more I find out, that there really is no easy out in the graphical world. If you really want it to look and work well.. you still kinda just have to do it yourself.. <groan and a smile>.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2710948
sunburnt

1 - Decide the lowest resolution you're going to support. 640x480 has become a bit too small these days. Many applications do not support resolutions lower than 800x600. Anyway, the choice is yours.

2 - Design your screens for that resolution.

3 - Do NOT resize your screens at all for greater resolutions.

That's the behaviour of most standard windows programs, and it will be the behaviour that is most likely to meet with your customers' approval.


Some screens however can be resized by the user. In that case you may have to resize some controls, leave some controls alone, move some controls but don't resize them. A nice example of this can be found in:
http://homepage.eircom.net/~carafa/VBSamples/VB6/ResizeSample.frm

Hope this helps

Pino


0
 
LVL 2

Expert Comment

by:burntout
ID: 2711102
I agree with caraf q,
I use to risize every thing perfectly... Then one day I said screw it!
now I make all my apps 640x480
the only resizing option the user gets is normal and minimized.
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2711277
Resizing doesn't HAVE to mean resizing proportionally!!  

Eg, if you have a big multiline text box and two buttons under it, it's much nicer to be able to resize the form to read all of the text box than be stuck with those wanky MS-style tiny boxes where you only get to see 4 lines out of 400 and...(you get the picture).

The point being that the buttons can be MOVED but not resized, so they are effectively alligned to the bottom of the form instead of the top.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2711315
Nazdor <smile> did you check out my example?
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2711623
caraf - nope! :-P


I was refering to poor ole burntout's problem of not being nice to his users...

Instead of code every single form, I've got a control which allows you to align buttons(etc) to the right, bottom or bottom+right instead of merely resizing them (which, can I say again, looks sh.., err duff!)



PS.  ScaleLeft * 0  ??  :-)

0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2711629
sunburnt - have you tried using the 'Form Layout Window' (by default on the View menu).


Open it and then run your project - that lets you see where/how your forms are going to appear on lower resolutions - make sure they fit nicely before distributing them.


Alternatively, run dual screens - have one as a shitty old 14incher running at the end-users' res.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2711704
Nazdor, check it out then ;-) It does exactly what you're saying so you'll find that we're in perfect agreement on that one. But it does it through code only, which is a bit more flexible than by using some OCX control. It's a bit more work, granted. But once it works, it works, and if it don't, well, it's *your* code, so it's *your* bug, so *you* should be able to fix it. I like that. <G>
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2711710
Another thing. Don't just design for lowest resolution. Also, try out Font settings. What if your user is on the smallest possible resolution and decides for some strange reason to use Large Fonts?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2711718
(ps - last comment directed to sunburnt)
Nazdor, don't worry - code has been on web page for a while now and has always passed our company virus checks that are updated regularly.
0
 
LVL 11

Accepted Solution

by:
bmatumbura earned 75 total points
ID: 2712803
I'd suggest that you develop your application at a lower screen resolution like 640 X 480 so that when your resolution increases, your forms won't be too big. There is also a nice tip at the following URL:

  http://www.vb-world.net/tips/tip46.html
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2715005
bmatumbura,

Please read my comment of : Thursday, April 13 2000 - 08:50AM IST

Then, kindly withdraw your answer
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2715426
caraf - well, it's also *MY* - as you would put it :-) - OCX - so when..err...if it doesn't work I can fix it.

I'm just lazy - prefer to do things once and then not have to do it again, so I literaly just add the control and set the tag to "AB" and from then on it's aligned to the bottom (AR for right, S for sizing etc).
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2715464
Nazdor, that's fine - and please don't feel offended, no offence meant, but...

I'm sure your OCX control is quite good, but I'm also sure that I can find a way to break it. That doesn't matter, like you said, you can fix it. But it means I have to chase you to get it fixed. What if you run into a tree tomorrow? What if you feel it doesn't warrant your effort to get my particular problem fixed? Then I'm stuffed.

And proper resizing code is what every VB programmer should be capable of writing. You shouldn't call yourself a VB programmer if you can't write simple algoritms like that.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2715465
Sorry, that last sentence sounded like it was directed at you, Nazdor. It wasn't. I should have said "One shouldn't call"... (etc)
0
 
LVL 1

Expert Comment

by:csameer1
ID: 2852798
Talking about this ,i just remembered a problem i faced,when i did a form sizing with the toolbar in a form,the postions of other controls placed just below it varied from that coded(reference was toolbar.height .I had to put the same codes in the form activate to get the sizing correct
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2857481
Looks like we've been wasting our precious time on sunburnt.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now