Placing Form in Output

My version of Visual Basic 6 insists on placing the form at the upper left
part of the screen rather than in the center when running maximized.  This looks terrible with large blank space at right.  Changing properties of form to center, etc does nothing.  I cannot get the Layout Window to show a form for placement  (It seemed to work OK on my previous Version 5). It remains blank with the dotted lines showing different display sizes, resisting my efforts to show forms there.  Help would be most appreciated!  There must be a way to get forms in the center.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

to center a form you can try
in the form load

me.left = (screen.width/2) - (me.width/2) = (screen.height/2)-(me.height/2)
set the forms default .StartupPosition property to "2-CenterScreen"

Please note that if you are showing your forms in the Form_Layout window, or if you're running an SDI version of VB, and you move the forms either way, VB will "kindly" assume that you want to set the form position manually, and you loose any StartUpPosition setting you may have applied earlier.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

forrestxAuthor Commented:
With thanks to crazyman, caraf g and mark2150, I am sorry that none of ideas work yet.  Forms are centered in normal mode.  But when maximized at level 2 they insist on displaying at top left of screen.
As in my question, I tried all combinations of the properties, as each startupposition as centered, etc. Nothing. The form commands as me.left, do not work at all here whether form is normal or maximized.  I tried placing suggested  me. commands as per crazyman before and after the windowstate=2 to max the forms, in calling form and displayed form and both, still NOTHING.  I am in SDI, and the Layout window does not work here.  I presume this is for MDI. Suggestions most WELCOME.  I am really stuck!

Wait a sec... you're maximising the forms... but then surely they should take up all the full screen?
forrestxAuthor Commented:
For caraf g:  On your question, no, the
maximized forms do blank out the whole screen, but on my 21 inch monitor(1024-768) the form material per se goes to the top left corner with much of the display screen blank to right and bottom. The form material shows in about same size as in normal display. Setting down resolution to usual 800/600 level forms now take much more space maximized but still do same thing, not centered properly. Thanks
Sounds like a monitor settings issue and not a programming issue. If the forms are maximized they should start at 0,0 in the upperleft. If you're compiling at one rez and then running at a higher rez and the screen is shifting I'm betting that the same thing will happen if you manually force the rez up on the desktop properties page and has NOTHING to do with VB. Many monitors change their displayable area as their resolution changes. Is one reason that dynamic resolution changes is NOT a good idea. If you fiddle with height/width knobs on monitor problem should go away. But if it is severe then is indication that monitor is being overdriven and may not tolerate being at that rez for long. If you smell smoke, lower the rez *FAST*.

Aha, I get you now!

Maximizing the form only maximizes the form. It does *NOTHING* to the controls on the form. These will therefore remain in the exact same position relative to the top left hand corner of the form.

On a high-resolution screen you'll therefore necessarily get a form with all the controls seemingly "squashed up" in the top left hand corner. This is normal.

There are several ways around this, but all of them involve recalculating control positions and sizes in the Form_Resize procedure.

The *BEST* way of doing this is manually, because it leaves you full control over your form's look and feel.

Generally speaking, when your form is resized, you should not resize static controls: buttons, check boxes etc. These controls may be repositioned but NOT resized. Controls that may be resized are controls such as list boxes/list views, tree views and the likes.

There also are 3rd party activex components out there that claim to be magical solutions to this problem. IMHO they are all utter crap. DIY is my advice. You'll learn something and if it doesn't work, it's YOUR code that's causing the problem so it CAN be changed.

Hope this helps...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
forrestxAuthor Commented:
I better do that again:  You finally put me on the trail of the solution.  Nothing on resizing is in the big expensive books on VB here, and the VB help as usual is near useless on this. I am dismayed by the massive amount of code needed to center max every control top and left -with many forms 15-20 or more controls on this project- and twice again to make them go back to normal.  Isn't there a better way?  Also we need to modify for different screen resolutions and the info in the VB help on this is useless - I get same twipsperpixel on every resolution, we need to get something different on each.  Comments most welcome

Yes, it definitely is not easy, but there are some tricks you can use to make your life a little less difficult.

Heck, you know what.... I'll write a little example program with a form with a few controls on it and I'll post it on my web site.



TwipsPerPixel, despite the explanation in the help text, hasn't much to do with your screen resolution. In theory there could be many different values for TwipsPerPixel, but in practice I don't see much of that. In actual fact, I've only ever seen two values "in the wild", and these depend on the font size chosen in the display settings on your computer. On all computers I've seen so far, the small fonts setting corresponds with 15 Twips Per Pixel, and the large fonts one with 12 Twips Per Pixel. Maybe, just maybe, there may be different values for hand-held thingymajigs or laptops.

So TwipsPerPixel is completely independent of screen resolution. Whether 640x480 or 1024x768, you'll always get 15 or 12 depending on the font size the user chooses.

The way to check screen resolution is via screen.height and screen.width
Height in pixels = screen.height / screen.twipsperpixely and you can guess what the screen's width in pixels is.

Hope this helps.

When I've done the example I'll post the URL here.
Dynamic control resizing has often been a topic of discussion here. The general consensus of the experts is that you should setup your forms for a specific resolution - state that on the outside of the box - and leave it at that.

You can dynamically resize your forms and controls but this is more often perceived by users as a *bug* instead of a *feature*. If a user is bumping up their rez they generally want *more* on their screen. If your app automatically "grows" to eat more screen space you're fighting the user instead of helping.

One thing I do is disable the maximize button. This prevents the form from growing to take the full screen leaving my controls clustered in the corner. You can still minimize the form into the taskbar and expand it back up, but it won't grow larger than it's design size.

When you resize the controls adjusting the .Top and .Left as well as the .Height and .Width properties isn't that hard. The problem comes in when you're trying to scale the text. There is no clear relationship between the point sizes of text and the dimensions of the text in twips. This means that your controls will either have tiny text or oversized text at any "non-standard" resolution. Giving you a weird looking and possibly unusuable app.

Anyway, for my apps I set the screens to look nice at 800x600 and leave it at that. When they run at 1028x768 or some other rez my app doesn't fill the screen. Without the maximize button I still look ok proportionally and the users have more screen real estate. The only time that I take the full screen no matter what is when I'm showing pictures or wallpaper.

It's a very simple example but it hopefully covers the essentials.
forrestxAuthor Commented:
  I got your form and idea, have saved it here and will be playing with it
to see how it can help
   Thanks much again

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.