开发者

User Control that acts like a standard Window, only confined to a pane

开发者 https://www.devze.com 2023-03-17 05:16 出处:网络
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 contai

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 开发者_StackOverflowstore 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:

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

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


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


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.


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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消