Hi,

I'm working in C# Windows Forms, with an MDI system. My documents contain several different objects. I want those objects to be shown as dragable windows *inside* the document (MDI client) window, and to be part of that window (ie scroll with it, affect the scroll bars, etc). I've tried to add the windows as children of the MDI client window and I get an error. I've also tried a bunch of other things, none of them work.

Is that possible, or do I have to create several controls to fake it?

I'm not married to the MDI, I just used it to get this to work.... SDI would be fine if I could get #(@!$ child windows to work....

Thanks in advance,

Joe

Well, Joe, I'm new to C#, and I think it's kinda troubling that no one's responded yet to your query.
Basically, the process you seem to be describing can be implemented by setting the "IsMdiContainer" property of what will be your parent window to TRUE.
Then, you create your child objects normally, and whatever control (button or menu) you use to open an instance of a child object, it should have code similar to the following:

protected void MDIChildNew_Click(object sender, System.EventArgs e){
Form2 newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}

"Form2" is the name of the child object. This should cause the child object to exist within the confines of the parent window. My only problem with this concept is the lack of control (as far as I know) over the position of the child objects; they cascade by default, which I would rather they didn't do.

There might be easier ways, but this process has worked for me. Hope this helps!

Dear Toulinwoek, (I'm curious about this name, by the way)

Thanks for your kind reply to my question; I was beginning to wonder if I had some kind of special invisible posting account!!

That said, my question was quite esoteric, so not totally surprised.

The process you describe sets up client windows inside an MDI app. I agree it has its limitations, one of which is that when you use it, it's difficult to put windows inside the MDI client windows - if you try to create a form there then you get an error saying you can't add a top-level form to a child form, or something like that.

Fortunately, after several days of searching, and a lot of people telling me
it couldn't be done (not to mention some unanswered posts), I just found out how to do it, which I include for others struggling with this problem:

Forms.frmTest oMyForm = new Forms.frmTest();
oMyForm.TopLevel=false;
this.Controls.Add(oMyForm);
oMyForm.Show();

This, then, allows a top-level form (ie a window) to be added to another window without an error. The bold line is the crucial one.

In addition, I found the following :

There is setting in Options that is hiding some properties.

Go to Tools->Options->TextEditor->All Languages and Uncheck the Hide
Advanced Members CheckBox. . .

The latter didn't seem to make a difference for me, but might help someone
else.

Thanks again for your kind help on this one - it's good to know there are people out there who answer questions....

Have a good one.

JamesCC

Ah, OK. Now I see; I wasn't fully understanding what you were trying to do, so thanks for sharing what you found. I'll add it to my code library right away!

This article has been dead for over six months. Start a new discussion instead.