Controlling a forms location within another form?

Posted on 2014-08-08
Last Modified: 2014-08-28
I have an MDI Form (Form1) that calls MDI Child Form (Form2). This Child Form calls another Form (Form3) which in turn calls another Form (Form4).

What I need to be able to do is make Form4 be centered in Form3. Using the "StartPosition" property for Form4 doesn't work because it's not a Child form to least it's "IsMDIContainer" property is set to False. Is there a quick way of doing this using properties or do I need to calculate it?

Question by:BlakeMcKenna

    Author Comment


    I'm taking a different approach altogether. I'm not going to use a form, rather an "Inputbox". However, what I need to do is determine the coordinates of a textbox in Form3 relative to where it is on the screen and not it's parent form. I thought using the "Point" Class but I may not be using it correctly and I can't find any examples.
    LVL 40

    Accepted Solution

    Actually, it is easier to do with a Form than it is with an InputBox, because you know the size of the form and you do not know the size of an InputBox.

    You could always get the size of the InputBox by trial and error, but since it is not documented, this is something that might change in a future version of the framework. Also, the InputBox is part of the Microsoft.VisualBasic namespace. It is usually better to use the framework own features instead of relying on those that were designed to ease the transition from the old VB.

    Also, note that Point is not a class, it is a structure. There are differences in the way they behave and the way you use them. You might want to give a look here in order to learn about the differences.

    In order for code like the following to work, you must make sure that the StartPosition property of Form4 is set to Manual. Any other setting will override your own Location. The idea is simply to calculate half the difference of Width between the 2 forms, and use that as an offset from the Top and Left of the first form, something like the following, assuming that Form4 is created and shown from the form in which you want to center it:

    Dim frm As New Form4
    frm.Location = New Point(Me.Location.X + CInt((Me.Width - frm.Width) / 2), Me.Location.Y + CInt((Me.Height - frm.Height) / 2))

    Open in new window


    Author Closing Comment

    Thanks James..that worked!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now