dcsimg
Results 1 to 9 of 9

Thread: MDI Location Of Child Forms?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    64

    MDI Location Of Child Forms?

    Hi I have some questions about MDI child forms, I am not sure I am doing it right but so far I have my main form, form1 set to IsMdiContainer = True
    and in the form1:

    Code:
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Form2.MdiParent = Me
            Form2.Show()
        End Sub
    End Class
    I think this is correct so far but was wondering about the form2 settings? Is there anything I need to set there for the form to be a child of the main MDI form or any other code I should set for that? ok well now I want to position some of the child forms in the main MDI form. I was going to set the position manually but I figured that it would change on other users screens depending on their screen resolution so how can I set this so it will always basically look the same no matter the screen resolution?

    For example I want my form2 to load in the main MDI form but in the upper right side, not quite at the very top but under a toolbar section.

    One other problem I was noticing was the form2 when loaded inside the form1 MDI form and dragged around by the edges it does not stay inside the form1 container, is there a way to make sure it can not go off the screen like this?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: MDI Location Of Child Forms?

    You need to start by setting the child form's StartPosition property to Manual and then you can set the Location or Top and Left properties. As for what to set them to, it's fairly obvious if you have learned basic geometry and arithmetic in school. If setting the Top to zero hides part of the child form under a ToolStrip (not sure if that's the case as I haven't tested) then you simply set it to the Height of the ToolStrip. As for the Left property, that needs to be the Width of the child form less than the Width of the parent form's ClientSize. You use the ClientSize rather than the Size because the latter includes the border and title bar.

    There's no simple way to prevent an MDI child form being dragged beyond the bounds of its parent, i.e. you can't just set a property. You would have to handle the appropriate event(s) and then change the Location or Top and Left properties of the child form accordingly. That would mean the LocationChanged of the child and the SizeChanged of the parent.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    64

    Re: MDI Location Of Child Forms?

    Thanks jmcilhinney, Right ok yes I have the child form set to manual and have set the position (still experimenting with the toolbar strip since I am not done designing but it is basically where I want it) alright and my main MDI form is set to load at windowstate maximized so I was worried that on other people computers since everyone uses different resolutions (smaller or larger) that it might not look the same? Would the proportions still stay the same or is this an issue that I need to fix somehow?

    ok the dragged out of bounds issue, you would think this would be an issue fix or even a non issue as there really is no reason to have the form drag outside of the mdi parent. Microsoft should fix that, why on earth would anyone want to have it do that? I am not sure.. ok well anyway I was hoping to have it so the child forms that are in the MDI container, when the edge of the form hits what should be the end of the mdi parent form size it locks the form in the boundaries. if the end of the mdi form was a wall you would expect to not be able to go through it.. how would I go about fixing this issue? Seems like it should be an easy fix.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: MDI Location Of Child Forms?

    It's like you didn't even read my previous post. I told you what to do one both counts and you've apparently made no attempt to follow any of those instructions. If you're waiting for me to write your code for you, I'm afraid that you'll be waiting a long time. If you try to follow my instructions and you have issues then I'm happy to help you try to solve them. If you're not prepared to make an attempt then we're done.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    64

    Re: MDI Location Of Child Forms?

    ok please forgive me I am still new to programming and don't know much. I am not asking you to write it for me, I am just not quite sure I understand what I need to do. I am assuming from what you said that I need to write the code for this into the locationchanged section in the form properties..

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: MDI Location Of Child Forms?

    I answered two questions. The first was about setting the initial location of the child form. That has got nothing to do with any events. It's just part of configuring the child form before displaying it, just like setting its Text property if you want something specific in the title bar. The second involved events and I described exactly what needs to happen:
    You would have to handle the appropriate event(s) and then change the Location or Top and Left properties of the child form accordingly. That would mean the LocationChanged of the child and the SizeChanged of the parent.
    You don't have to assume anything. You just have to do as described. Handle the LocationChanged event of the child form and the SizeChanged event of the parent form. If the child form is outside the bounds of the parent then set the appropriate property to move it back inside. Determining whether the child is outside the bounds is simple arithmetic.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    64

    Re: MDI Location Of Child Forms?

    ok I did manually set the position of the child form no problem there.. ok I am still new to programming like I said ok so I am thinking in the locationchanged of form2 I start with something like this:

    If Form2_LocationChanged() =

    what the argument here is I do not know, somehow I need to say, if form2 is off the screen "then" do.. and then somehow block if from going off the screen.. I remember a little bit about statements like that but I have not been involved in programming since VB6 many years ago so I am sorry if I am coming off a certain way. I want to learn I just need some help understanding this. Thanks

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: MDI Location Of Child Forms?

    Quote Originally Posted by DreamWarrior77 View Post
    I want to learn I just need some help understanding this.
    I suggest you do a bit of reading on the basics of VB.NET programming. We should be able to say something like "handle the X event" and you should be able to do that because handling events is fairly fundamental to VB.NET programming, much like getting and setting properties and calling methods. Which event to handle in a specific case is one thing but I don't think that it's our job to teach each person the fundamentals of programming. There are plenty of resources for that already. I suggest that you follow the tutorial link in my signature below and work through that first. When you have done that, you will know what it means to handle an event, among other things.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: MDI Location Of Child Forms?

    You also need to learn how to make use of information you already have. You already know how to position a form such that it is in a specific location relative to the parent form's client bounds. Does that not give you any clues at all about how to determine whether a form is outside those bounds? You already have a good idea of what properties are involved and it's simple arithmetic from there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width