Controlling The Startup Position Of Owned Forms

Hello All,

I am having a bit of a problem with handling the positioning of several of my forms in my application. I am using an MDI Form as the main parent form. I am using the MDI Parent form for this purpose becase I want all the other forms to stay within the boundaries of the of the main application form and the MDI Parent form has served this purpose well form me in the past. This app will not be a traditional MDI app as there will not multiple instances of some forms, such as a login form, an about form, a splash screen and a change password form. I still want these forms to have a certain startup position in relationship to the MDI Parent form, ie, centered in the MDI Parent. I have set the start position property of these forms to center parent. Additionally I have used the AddOwnedForm method to assign the MDI parent form as the owner of the other forms. I have also tried setting the Parent property of these forms to the MDI Parent. This method produces a compile time error. When the application is run, these forms appear in front of the MDI Parent, as they should, but they are outside the boundaries of the MDI Parent and they certainly are not centered within the MDI Parent. I would be very grateful if someone would be kind enough to provide some guidance as to what piece of the puzzle is missing here. I am really puzzled here. Although I think I already know that the answer to the problem is a customized CenterForm function. I am trying to avoid this solution if there is a solution accessable elsewhere though setting the correct properties within my code. Any help you can offer would be greatly appreciated. Thanks In Advance.

Regards,

V. Shane Curtis




Answer this question

Controlling The Startup Position Of Owned Forms

  • kowalsky

    Steve,

    The forms in question are the ones that I do not want treated as MDI Child forms. I will try the MDIParent property anyway.

    Thanks for the help

    Shane



  • Kandikan

    Hi Shane,

    AddOwnedForm does not make the form an MDI Child, it simply sets ownership to the MDI parent. You should instead use MdiParent:

    Dim childForm As New loginForm

    childForm.MdiParent = parentForm

    childForm.Show

    Although the documentation for the StartPosition property claims that it works for MDI forms, I can't seem to make it work, but you can easily write your own function to position the child form by measuring its height and width and comparing to the parent's height and width.

    Hope this helps,

    Steve Hoag

    Visual Basic Express



  • Controlling The Startup Position Of Owned Forms