1

I'm making a program to generate code for me, and I'm fashioning the UI after Game Maker due to how easy the interface is. It has a SplitContainer with Panel1 containing a TreeView and Panel2 containing an arbitrary amount of self-contained windows (real windows, not some hacky workaround). I wanted to use user-controls to store the controls I use to modify things, but I can't figure out any way to put it in a window inside the splitContainer's Panel2. Can anyone help me?

Here's a good example:

https://i.stack.imgur.com/CG6kO.png

Those two sprite property windows are what I'm trying to do.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Eagle-Eye
  • 1,468
  • 2
  • 18
  • 26

4 Answers4

2

i think what you are looking for is called mdi-container

however the only real mdi container i've seen so far (in .NET) is a form ... sadly no panel or something similar...

but if you just want the "window in a window" effect: simply create your new form, set the TopLevel property of that instance to false, and add the instance to your form/panel/splitcontainer/whatever like any other usual control

DarkSquirrel42
  • 10,167
  • 3
  • 20
  • 31
  • It's not `TopLevel` that controls MDI containment, but the [`IsMdiContainer`](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.ismdicontainer.aspx) and [`MdiParent`](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.mdiparent.aspx) properties. – Ben Voigt Jul 04 '11 at 00:52
  • @ben yes ... but MDI seems to require that the parent container is a Form, and nothing else. i haven't found a way to create a true MDI application that uses only a limited area on a form for MDI child windows. if OP just needs that "window in a window" effekt, creating a form with TopLevel=false, that can be used like a regular control, might be sufficient – DarkSquirrel42 Jul 04 '11 at 06:07
  • As Stuart said, docks within the parent form limit the area within which the MDI children can roam. Don't know any simple way to have multiple sets of children each within a distinct area of the parent, but it doesn't seem like Eagle-Eye is asking for that. But setting `TopLevel = false` just turns the form into a popup window, preventing it from appearing in the taskbar. It doesn't limit its position to the owner. – Ben Voigt Jul 04 '11 at 13:31
  • @ben ... ok, and after setting TopLevel to false, try adding the Form to the Controls Property of a Panel ... – DarkSquirrel42 Jul 04 '11 at 16:11
1

You could try using an MDI form and to implement your TreeView control, check out some sort of docking panel. I've used this one in the past (http://sourceforge.net/projects/dockpanelsuite/).

It is very flexible. You set up one of these dockpanel forms, docked to the left of your MDI form. It will always be "on top" and the user can resize it exactly like the splitter control on a form. If you like, it can also has an "autohide" feature which may or may not be desirable in your case.

It can then contain you treeview, which can load all the MDI Child forms you like.

You'll find you're not fighting how "Windows" really want to behave and things will run a lot more smoothly.

Stuart Helwig
  • 9,318
  • 8
  • 51
  • 67
  • This seems to be exactly what I need. Also, thank you for linking to something with the MIT license. That and zlib/zpng are my favorite licenses. – Eagle-Eye Jul 04 '11 at 11:35
  • The library wound up not working, but I found out that I *can* make an arbitrary amount of Forms; in the MDI parent's constructor, add "IsMdiContainer = true;". Then go: "newwindow = new FormNameGoesHere(); newwindow.MdiParent = this; newwindow.Show();" whenever you want to make a new MDI form. – Eagle-Eye Jul 04 '11 at 22:51
0

Put it into the Panel2's Control collection via the Add() method, apply coordinates, anchor and docking programmaticaly.

Denis Biondic
  • 7,943
  • 5
  • 48
  • 79
  • I know how to add a user control progmatically; I need to know how to add a user-control that's in it's own window, but still inside the panel progmatically. – Eagle-Eye Jul 03 '11 at 23:34
  • If you have a UserControl inside the form, embedd, then put that UserControl in the Panel2, not the whole form? – Denis Biondic Jul 04 '11 at 06:47
0

I did similar thing once, and for that reason, I have ReplaceControl method, which I paste below:

    static public void ReplaceControl(Control ToReplace, Form ReplaceWith) {
        ReplaceWith.TopLevel=false;
        ReplaceWith.FormBorderStyle=FormBorderStyle.None;
        ReplaceWith.Show();
        ReplaceWith.Anchor=ToReplace.Anchor;
        ReplaceWith.Dock=ToReplace.Dock;
        ReplaceWith.Font=ToReplace.Font;
        ReplaceWith.Size=ToReplace.Size;
        ReplaceWith.Location=ToReplace.Location;
        ToReplace.Parent.Controls.Add(ReplaceWith);
        ToReplace.Visible=false;
    }

Only thing left to do is to create some control manually on the form, as the placeholder for your Form. Use label, for example.

From How to implement a-form-inside-a-form with runtime embedded forms switching?

Community
  • 1
  • 1
Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99