Results 1 to 17 of 17

Thread: Center a Form inside MDI

  1. #1

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71

    Center a Form inside MDI

    Hi All,

    I am not able to center any child form inside the main MDI form, even with the use of the "StartPosition" in design properties.

    Any idea?
    Thanks for any help...
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  2. #2
    New Member
    Join Date
    Nov 2002
    Posts
    15
    Might try to position the form like so:

    VB Code:
    1. Form1.Left = MDIForm1.Width / 2 - Form1.Width / 2

    Have you been sure to access the mdiForm's left property instead of the childForm's left property?

    Make sure to put that code in the Form1_Load event, AND the mdiForm1.resize event. Wouldn't put it anywhere else unless you want to annoy people who want to move the form

    I have attached the code and the form. Don't forget to reply to this thread if it works (or even email me for that matter)
    Attached Files Attached Files
    Last edited by NomadtheGrey; Nov 19th, 2002 at 08:55 AM.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    the above code will never works in VB.NET.

    If you want to do that in VB.NET then scroll down to the last post written by Me (Pirate)

    here is the link

    http://www.vbforums.com/showthread.p...hreadid=213750

  4. #4

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Hi NomadtheGrey,

    Pirate, is correct. the code you sent me is for vb6 and will not work on vb.net.

    Pirate, I checked your code ... wonderful ..

    Thank you for both of you.
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    the code and zip file sent by NomadtheGrey is VB6 , the one I sent is VB.NET.

    did you figure things out of that ??
    Last edited by Pirate; Nov 19th, 2002 at 04:44 PM.

  6. #6

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Yes Pirate, this is exactly what I need, thanks a lot.

    Movint to VB.NET is not easy, I was feeling good in vb6 days

    Pirate can you do me another favore please

    I posted a question titled "Database Note Updated !", can you help me out in that please.

    ADSC
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    umm , can I have a look at your project so far. Promise you to give it a shot

    send the project with db now ??

  8. #8

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    I can't send you the db because I am using MSDE not Access,
    I'll send you a small application having the same steps I am doing the the db project, okey??
    Attached Files Attached Files
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    i guess i can't work without the present of DB. you need to send the db as well , or am i wrong??

  10. #10

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Fine, if you have MSDE I'll send you the database name, table name & structure .. I think this is it all.
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    unfortunately I don't have . ,
    maybe others can help you to get out of this hell.bye

  12. #12

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Ok, thanks for your help and your time.
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    any time

  14. #14
    Addicted Member
    Join Date
    Oct 2002
    Posts
    174

    Centering form

    I think this is helpful for u


    'Centering the form
    Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 4

  15. #15
    New Member
    Join Date
    Nov 2002
    Posts
    15
    I apologize for sending VB6 material on a vb.NET forum. I wasn't paying close enough attention to what I was doing.

    However, you can open the project in .NET anyway, which will translate it into pseudo-equivalent code. The only exception with this particular project was with the statement

    VB Code:
    1. load Form1
    2. Form1.show

    .NET doesn't support it, because .NET doesn't need it. I commented it out, and the altered code was identical in function, if different in appearance. It went like so:
    VB Code:
    1. Form1.DefInstance.Show()
    2.        
    3.         Form1.DefInstance.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(MDIForm1.DefInstance.Width) / 2 - VB6.PixelsToTwipsX(Form1.DefInstance.Width) / 2)

    Of course, such strange translation is hardly necessary. I wrote much more concise code as follows, using .NET:

    VB Code:
    1. dim mdiChild as new Form2()
    2. mdiChild.mdiParent = Me
    3. mdiChild.Show()
    4. mdiChild.Anchor = AnchorStyles.None
    5. mdiChild.Left = Me.Width /2 - mdiChild.width /2

  16. #16

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71

    RESOLVED

    Thanks NomadtheGrey..

    I got the idea from Pirate's code, I was missing one thing ... to subtract the docking size, then it'll be okey...

    Thanks again....

    ADSC
    Last edited by adsc; Nov 20th, 2002 at 10:14 PM.
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  17. #17
    New Member
    Join Date
    Nov 2002
    Posts
    15
    Don't forget to put RESOLVED in the subject line now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width