Link to home
Start Free TrialLog in
Avatar of sunburnt
sunburnt

asked on

Resize forms automatically when display resolutions changes

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.
Avatar of wsh2
wsh2

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
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.
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>.
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


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.
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.
Nazdor <smile> did you check out my example?
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  ??  :-)

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.
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>
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?
(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.
ASKER CERTIFIED SOLUTION
Avatar of bmatumbura
bmatumbura

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
bmatumbura,

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

Then, kindly withdraw your answer
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).
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.
Sorry, that last sentence sounded like it was directed at you, Nazdor. It wasn't. I should have said "One shouldn't call"... (etc)
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
Looks like we've been wasting our precious time on sunburnt.