Results 1 to 8 of 8

Thread: Multiple control boxes in parent/child forms

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    7

    Multiple control boxes in parent/child forms

    I've inherited a VB .NET project which I'm trying to sort through. There is a parent (MDI) form with several child forms, which are called via a treeview.

    The first problem I'm trying to solve is that there is a control box on the title bar, and another on the menu bar, right underneath it.

    The minimize/maximize and close buttons on the title bar work as they should, and will close the app, resize, etc. I want to leave these alone.

    The "Close" button (the "X") is greyed out on the menu bar, and I figure that might give some clue. But the "minimize" and "resize" buttons work, and they will resize the child forms inside the parent form.

    I'm trying to get rid of these controls (for the child form) that are on the menu bar entirely. I've set them to "false" in the properties of each form. I've gone through the code and cannot find where they might be reinitialized. Also, when I click a node on the tree and load a new child form, it seems to redraw the main form's title bar, the control boxes, etc. It seems as though the forms themselves aren't loading properly, though they do load.

    I've tried using code like the following:

    Dim NewMDIChild As New Form
    Dim activeChild As Form = Me.ActiveMdiChild

    NewMDIChild.WindowState = FormWindowState.Maximized
    NewMDIChild.ControlBox = False
    NewMDIChild.MinimizeBox = False
    NewMDIChild.MaximizeBox = False

    I'm stumped, at this point, and thought somebody might have a clue as to where I might look for this. I can post code here, but we're talking about a lot of lines of it, and I'd like to first try to figure out where I should be searching. Thanks a lot.
    Last edited by jegenes; Jun 4th, 2005 at 11:42 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    7

    Re: Multiple control boxes in parent/child forms

    I'll try to update my question a bit here. When repopulating the combo boxes in a child form like this when you click on a new node in a tree: Should it destroy the old form and make a new instance of it, or should it just repopulate the old one with new data? Seems like repopulating it would be less work on the cpu, hence faster. No?

    I'm pretty sure this code is creating a new instance every time. Thanks.

    John

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multiple control boxes in parent/child forms

    I'm pretty sure you cannot get rid of those buttons. If you want to make sure a child form is always maximised, I think the only way is to check the WindowState property in the Resize event handler and if it's not Maximized then set it to Maximized. I think that the reason for this may be that it avoids situations where you cannot access a child because it is hidden behind another, maximised child.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    7

    Re: Multiple control boxes in parent/child forms

    >>> I think that the reason for this may be that it avoids situations where you cannot access a child because it is hidden behind another, maximised child.<<<

    Hmmm.... I'm just trying to create a treeview type set of windows, much like Windows Explorer, except that the child form that pops up will have some data in it that it gets from the database connection. Maybe I'm missing something here... Wouldn't the normal way to do it be to have a tree (on the lefthand side), with a splitter, and then the child form opening on the righthand side? If there's a choice in the properties section of the child form for showing/not showing the control box buttons, why can't I just turn them off?

    The tree goes no further than 5 deep, so there are a total of 5 child forms, and the parent form. I'm thinking that maybe I should always have all 5 forms open, with a default one on top. Then, when the user clicked on any node, that child form would be shown and populated. Also, I'd probably want to dispose of the data in it when it wasn't the active form. Does this make sense?

    Of course, it's all the more confusing to me because I didn't write the code in the first place. Am doing damage/bug control, which probably isn't my strongest suit. And a good part of the code is written in Dutch, so I'm having to guess at what certain labels mean. [grin] Thanks

    john

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multiple control boxes in parent/child forms

    It sounds like, if you don't already, you should have the TreeView docked to the left-hand side of your parent form. Remember, the reason for using MDI is so you can have easy, controlled access to multiple documents/forms. If you specifically only want to use one child at a time it is more proper to open them as modal dialogue boxes rather than MDI children. If you open all your MDI children with a WindowState of Normal, a Fixed BorderStyle and no ControlBox then your windows will not be able to be resized or maximised. I don't know exactly what all the thinking behind the MDI mechanism is, but remember that if one child is maximised then they all are and if one child is restored to Normal they all are. I did once find a way to achieve what you want but, if I remember correctly, the buttons were there initially and they would only go if the user restored the window to Normal and then I maximised it again in the Resize event handler. It was a kludgy and ugly solution. Perhaps this is a bug in the framework or maybe Microsoft has a specific reason for this. You could check the knowledge base and if you don't find anything report a bug and see what happens.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    7

    Re: Multiple control boxes in parent/child forms

    >>> If you specifically only want to use one child at a time it is more proper to open them as modal dialogue boxes rather than MDI children.<<<

    Actually, this is exactly what I should be doing. Can I change their properties to make them into modal dialogue boxes, or do I need to just start over and create them that way from scratch. I want them to be maximised all the time, with only one showing at any given time. I'm pretty sure the tree is docked to the lefthand side of the page, although I haven't really checked for that yet. I'll look into that as well. Thanks for the ideas. I'll let you know.

    And yes, I think there might be some sort of bug in what I'm trying to do. The fact is, that one of the forms, the "inner-most" one (the 5th one in, on the tree) comes up without the control boxes, etc. It behaves just like the other is all other ways, and I can find nothing in the code to set it apart from them, but it doesn't have the open/close/resize buttons on it. Go figure....

    Thanks again.

    john

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multiple control boxes in parent/child forms

    If you want to use modal dialogues instead of MDI, these are the steps you should take:
    1. Set the IsMdiContainer property of the parent to False.
    2. When the children are created do not set their MdiParent property.
    3. call ShowDialog on a child to display it rather than Show.
    Note that ShowDialog returns a DialogResult value, which is normally used to determine what button was pressed to close the child. If you have an OK and a Cancel button, you would normally set their DialogResult properties to, you guessed it, OK and Cancel. You may also want to do some processing in the Click event handler of the OK button. After ShowDialog returns, the parent still has access to the child's (public or friend) properties.

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    7

    Re: Multiple control boxes in parent/child forms

    Thanks so much for the tips. It'll take me a few days to get through it, over the weekend, but I'll get back and let you know how it's going. By the way, I see you're in Australia. I'm a yank, living on the South Island in New Zealand, so we're almost neighbors! [grin]
    cheers...

    john

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