I've had a similar problem in the past.
What i did first was switch from inheriting Usercontrol to tabpage like so
class UserInterface : UserControl // Do designer bit then change it to
class UserInterface : TabPage
Second i Just put all my controls and stuff in the usercontrol and docked that into a tabpage.
third i've made a generic class that takes any usercontrol and does the docking automatically.
so you can take your 'UserInterface' class and just get a type that you can add to a System.Windows.Forms.TabControl
public class UserTabControl<T> : TabPage
where T : UserControl, new ()
{
private T _userControl;
public T UserControl
{
get{ return _userControl;}
set
{
_userControl = value;
OnUserControlChanged(EventArgs.Empty);
}
}
public event EventHandler UserControlChanged;
protected virtual void OnUserControlChanged(EventArgs e)
{
//add user control docked to tabpage
this.Controls.Clear();
UserControl.Dock = DockStyle.Fill;
this.Controls.Add(UserControl);
if (UserControlChanged != null)
{
UserControlChanged(this, e);
}
}
public UserTabControl() : this("UserTabControl")
{
}
public UserTabControl(string text)
: this( new T(),text )
{
}
public UserTabControl(T userControl)
: this(userControl, userControl.Name)
{
}
public UserTabControl(T userControl, string tabtext)
: base(tabtext)
{
InitializeComponent();
UserControl = userControl;
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// UserTabControl
//
this.BackColor = System.Drawing.Color.Transparent;
this.Padding = new System.Windows.Forms.Padding(3);
this.UseVisualStyleBackColor = true;
this.ResumeLayout(false);
}
}