Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
User Controls Again
Message
General information
Forum:
ASP.NET
Category:
Class design
Title:
User Controls Again
Miscellaneous
Thread ID:
01397235
Message ID:
01397235
Views:
84
I'm feeling frustrated because I cannot get this to work:

I want to create a series of user controls that will be added to a form at runtime. They will obviously need to have certain similar properties and methods such as Setup() and SaveChanges();

So I first tried this:
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:

I first created an interface:
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, IPanel
Then 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.

Someone help!
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform