Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centering things on a form when the form is maximised

Status
Not open for further replies.

SkennyR

Programmer
Mar 7, 2004
157
US
I have a form with two list boxes, a couple of command buttons, and a few labels.
The form starts up in normal windows position.
If I maximise the form, all the items (list boxes, etc.)
appear in the upper left corner. It is like the form expands to the right and down to fill the screen, but all the other things stay the same.
Is there anyway to leave all the things in the center of the form wheter the form is normal or maximised?
 
To keep a control central on resizing the form try:
Code:
Private Sub Form_Resize()
Command1.Left = (Me.Width - Command1.Width) / 2
End Sub
You could put all/some of your controls in a frame if you want to keep the relative positions constant, and just reposition the frame on Form_Resize


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks, since I have so many items on the form, I think I like the frame idea better, but one question:
How do I move everything already on the form to the top (or front?) of the new frame?
If I draw the frame on top of all the items, the frame covers them.
I hate the idea of deleting all the items and re-drawing them on top of the frame.
 
What you can do is:
1. drag your mouse over all controls that you want to move to the Frame - this will select the controls.
2. Edit - Cut, that will put all selected controls into Clipboard
3. Place your Frame on the (empty) Form
4. Select new Frame and Edit - Paste all controls from the Clipbaord.

You are done :)

---- Andy
 
The Form file is a simple text file which can be edited in Notepad or Textpad etc. The first item in the file (after header and any Objects) will be the Form object which is the outer container for everything, so you will see the Begin Form statement and its properties. Next comes all the other controls on the Form. If there is a Frame (with any controls in it) then those controls will be nested inside the Frame listing.
Begin Form
Form Properties
VB.Frame Frame1
Frame Properties
Controls in Frame here
Control End
Frame End
Non-Frame controls
Non-Frame control End
Form End

To move controls into a Frame just move the End associated with the Frame to the end of the Control properties

WARNING back up your form before editing, just in case!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks, cutting and copying to a new frame works great.
I set the frame.border to none and caption to none.
Then I entered this code:

Private Sub Form_Resize()
Frame1.Left = (Me.Width - Frame1.Width) / 2
Frame1.Top = (Me.Height - Frame1.Height) / 2
End Sub

Which is basically Johnwm's suggestion from above.
I added the top/height line to adjust the frame to the center vertically.
Again, I am endebted to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top