What is the difference between a user control and a windows form in Visual Studio - C#?
so is a user control!
Dave Markle
2010-02-19 20:34:25
how do you put a form into a user control!?
Fredou
2010-02-19 20:35:10
you can't, but you sure can put a user control in a user control.
Dave Markle
2010-02-19 20:35:43
@Dave - You can, actually. See my post.
Hans Passant
2010-02-19 20:40:54
+4
A:
Put very simply:
User controls are a way of making a custom, reusable component. A user control can contain other controls but must be hosted by a form.
Windows forms are the container for controls, including user controls. While it contains many similar attributes as a user control, it's primary purpose is to host controls.
asp316
2010-02-19 20:36:39
+4
A:
They have a lot in common, they are both derived from ContainerControl. UserControl however is designed to be a child window, it needs to be placed in a container. Form was designed to be a top-level window without a parent.
You can actually turn a Form into a child window by setting its TopLevel property to false:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
var child = new Form2();
child.TopLevel = false;
child.Location = new Point(10, 5);
child.Size = new Size(100, 100);
child.BackColor = Color.Yellow;
child.FormBorderStyle = FormBorderStyle.None;
child.Visible = true;
this.Controls.Add(child);
}
}
Hans Passant
2010-02-19 20:39:36