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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting X and Y Coordinates of a form when it loads

Status
Not open for further replies.

Aamin

Programmer
Oct 2, 2002
18
0
0
CA
I have a MDI form that holds several child forms. I need the child forms to open at a particular location each time they are loaded. So for instance, I have a maximized MDI form that has a menu bar across the top. When i choose File-New-Member, the New Member Screen will open within the MDI form. I need the Top-Left corner of the New Member Screen to open at a certain location (x,y) within the MDI form.

Any ideas?? Thx in advance...
 

If the forms are to load at the same location each time just set the top and left in the childs load event. These settings take the menu bar into account
eg
Code:
Private Sub Form_Load()
    Me.Top = 1000
    Me.Left = 2000
End Sub
 
Just my two penneth...

I wouldn't use .top, .left, etc - they tend to fire Resize and Repaint events. Depending on the complexity of your form, this can not only have a performance hit, it can lead to trouble (believe me ;-)!!) later.

Instead, I'd use the move method as follows:

Sub Form_Load()
'Move takes Singles for it's arg's
'either use Const's or "hardwired" values:
Me.Move sngLeft, sngTop, sngWidth, sngHeight
'or
Me.Move 10, 10
' for just X, Y positioning
End Sub

HTH !
 

Ive used the technique many times and have seen no evidence that positioning a form using .top, .left fire the events as you say.

 
SonOfEmidec1100,

It depends on the forms and controls that you're using. But trust me, .Move is a much better way to go. It's less "expensive" for one thing, and it's less code to write. For instance:

MyControl.Top = 100
MyControl.Left = 0
MyControl.Width = 400
MyControl.Height = 400

Compares to a single .Move statement

MyControl.Move 0, 100, 400, 400

Now even if you "with" block the four .Top .Left, etc, you're still creating expensive code both in calls and readability. Increase the number of forms/controls and you soon get hard to maintain code. I reckon .Move is the way to go when you're laying out or resizing a form, but you're welcome to your opinion.

All the best,

Comaboy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top