Moving from Form to User Control
I have a bunch of shapes that I insert into tabs (some are embedded two and three layers deep) which I suspect are giving me problems. I was told that User Control is the best approach.
-
Now I am wondering how I canaccomplish this as quickly as possible.
-
Is it as easy as copy and paste?
- Has anyone ever done something like this?
I have about 40 shapes that I pasted in that would need to be moved around and not long enough to get it done so any help would be much appreciated.
EDIT 1
This is how I insert the forms:
public static void ShowFormInContainerControl(Control ctl, Form frm)
{
frm.TopLevel = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.Visible = true;
ctl.Controls.Add(frm);
}
public static void DockControl(this Control control, UserControl userControl)
{
userControl.Dock = DockStyle.Fill;
control.Controls.Clear();
control.Controls.Add(userControl);
}
a source to share
Not sure if this is the "best", but it is probably the most efficient. Change the classes to inherit from UserControl
instead of Form
. Then fix compiler errors if / when you get them (see NOTE 2 below).
NOTE 1. If you are not using version control, start using it before doing something drastic. You will want to come back if things go too far south.
NOTE 2: If you are using any specific events or properties Form
that are not implemented in UserControl
, you will have to think about a solution. Some properties (for example Icon
) can simply be ignored (= remove line from constructor file).
NOTE 3: If you are using forms as an actual form somewhere, you will also want to have a form that uses the newly created UserControl. You will most likely run into naming issues, so be careful.
a source to share