We help IT Professionals succeed at work.

Changing startup position of a form display

jpp1jpp1
jpp1jpp1 asked
on
Medium Priority
170 Views
Last Modified: 2010-04-07
Let's say i have a huge form (almost full screen) and by default I want to load it in a compact mode ( a expand button would show it in full-size). Lowering height and width properties at loadup works fine but additionaly I want the compact mode to display a part of the form that is not at (0,0) instead it's somewhere in the middle. Changing top and left doesn't work, ir still starts drawing the form from 0,0 (top left).

I hope I made myself understandable. :P
Comment
Watch Question

Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
Form_Open

With frmYourForm
   .Left =   'Set the #'s here, in twips = 1/1440th of an inch
   .Top =
   .Width =
   .Height =
End With

Knock yourself out...
-Jim
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
(slight correction, I spent too much time doing Access)

Private Sub Form_Load()

With frmYourFormName
   .Left =   'Set the #'s here, in twips = 1/1440th of an inch
   .Top =
   .Width =
   .Height =
End With

End Sub

'Also, if you want to change the form's shape at runtime, I believe you can only do this by showing/hiding contents at the bottom/right of the form by adjusting .Width and .Height, as it will always anchor itself at 0,0.

Author

Commented:
No... Let's split the whole form in 9 parts:

   1  2  3
   4  5  6
   7  8  9

I want the compact form to just show block 5.
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
I think all that's possible is to dispay 1 or 1245 or 123456789, and not 5.   I'll step back and see if another expert has a solution for you.

Author

Commented:
Thx for your effort
Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
I'm afraid jimhorn is right.  Form resizing in VB occurs in the lower right corner.

The only way to do waht you want would be to reposition all of the controls on the form so that the bit you want appears in the middle when the form is in "compact" mode.


the scaleleft is what you are looking for

but be aware:

when you change this, the left of the controls changes with it,
so first change scaleleft and then position controls
Commented:
An easy solution is to add a picturebox (as a container) on your huge form and cut all the other controls on your form and paste them in the picturebox.

Now when your form is in compact mode you can control the parts that will be visible by changing the picturebox's left and top to suit your needs.

As an example, to show the center of the picture box:

Picture1.Left = (Me.Width - Picture1.Width) / 2
Picture1.Top = (Me.Height - Picture1.Height) / 2

This will position the container picturebox (picture1) in the center of the form.
You can add this code in the form_resize event

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.