private void _AddPanel(string sKey) { UserControl control; switch (sKey) { case "ship_items": control = new crlShipItems(); this.Controls.Add(control); control.Left = 0; control.Top = 0; control.Width = this.Width; control.Height = this.Height; control.Setup(); break; case "sview_inv": break; case "sreports": break; } }But this doesn't compile because there is not Setup() on a UserControl. So I tried this:
public interface IPanel { void Setup(); bool SaveChanages(); }I implemented the interface in the header of the Panel control's definition:
public partial class crlShipItems : UserControl, IPanelThen I changed the _AddPanel method:
private void _AddPanel(string sKey) { IPanel control; switch (sKey) { case "ship_items": control = new crlShipItems(); this.Controls.Add(control); control.Left = 0; control.Top = 0; control.Width = this.Width; control.Height = this.Height; control.Setup(); break; case "sview_inv": break; case "sreports": break; } }Not I get 5 compilations errors - one for each of the Top,Left, Width and Height, and on on the Controls.Add saying "The best overloaded method match for 'System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control)' has some invalid arguments", probably because it's no longer a control.