ugp

Is it possible to use a Form with in another Form

i:e like this;

There is a Form1.cs

I want to put another form (Say Form2.cs) on top of this Form1.

(should able to drag and drop Form2;...as a usercontrol or any other way)

It(Form2) should aslo support for getting controls (such as defauls buttons,labels etc.)

and generate the appropriate code as normally.

is it possible to do this kind of a thing

need help!



Re: Windows Forms General using a Form within a Form

beshaghy

Dragging one form to another is not possible as they are both top level controls. You should make a user control for the control you want to drag and drop between forms. User controls are basically forms with no menu bar, simplified explanation obviously, so you will have the functionality you described above by using a user control.



Re: Windows Forms General using a Form within a Form

all2neat

I think beshaghy is correct and that it sounds like user controls is what you are looking for but you can also try the MDI parent form.



Re: Windows Forms General using a Form within a Form

ugp

ok.

Is it possible to act a usercontrol like a Form.

for example; if put a Button on top of the usercontrol, it should detect it, and then it should generate its code in a seperate file..

(Not in the Form1.cs or Form1.Designer.cs; should be in a seperate file)

Coding like -> here; Button button1 = new Button(); and set location etc...etc...coding

is it possible to do something like that





Re: Windows Forms General using a Form within a Form

beshaghy

You could use a MDI layout, but you still wouldn't be able to drag a Form2 to a Form1. It really depends what business problem you are trying to solve.



Re: Windows Forms General using a Form within a Form

beshaghy

An user control acts like a form and has its own code behind and designer. When you add the user control to a form it is locked and can't be edited on the form at design time, you need to go back to the user control designer and edit it there. Are you talking about adding things at design time or runtime



Re: Windows Forms General using a Form within a Form

ugp

i mean in design time.

by using this kind of thing able to attach/group the controls together. but the problem is code generating part.

by nobugz

To be able to add controls to a UC after you've placed the UC on a form, you'll have to tell Windows Forms to use a different designer. Add a reference to System.Design, then make your UC code look like this:

Code Snippet
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Design;

namespace WindowsApplication1 {
[Designer(typeof(System.Windows.Forms.Design.ParentControlDesigner))]
public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
}
}
}


if able to get the generated coding...(ex: if button is put to the usercontrol, then there wil be some automatic code generated. if able to capture this code and write to another file, it will be done)

any idea to do this.....!!





Re: Windows Forms General using a Form within a Form

beshaghy

What he is suggesting to do is tell the UserControl to use the Forms designer and not its own designer to allow the drag and drop functionality. The solution he showed you doesn't work. A UserControl really shouldn't be edited after it is placed on the Form, that sort of defeats the purpose of a UserControl, which is to add Encapsulation and OOP principals to a piece of reusable code. Changing the UserControl in the manner you are talking about means it gets changed for every Form it is on not just the one you edited it on. This is a really bad practice and will cause confusion, why are you trying to do this in the first place What is the reason you want to store this info in another file Do you have to to use the designer You could create XML files that store what buttons etc. you want and then load those at runtime.