Embedding User Controls in a bad idea?

I embed usercontrols in a panel and using the DevExpress Navigator moves from one to the other. What am I talking about, are there any implications for this method?

I would give examples of what bothers me, but then I won't need to ask this question ...

I have a primary form, ShellForm, which has a docked Navigator Control on the left and a docked Panel control for the rest. Then I set a custom control like ucSearchPage on the panel when the link is clicked.

    public partial class ShellForm : XtraForm
{
    private ucSearch searchPage = new ucSearch();
    private ucEnrollments enrollmentPage = new ucEnrollments();
    private ucGeneral generalInfoPage = new ucGeneral();
    private ucContacts contactPage = new ucContacts();

    public ShellForm()
    {
        InitializeComponent();
    }

    private void ShellForm_Load(object sender, EventArgs e)
    {
        this.pnlShellHost.DockControl(this.searchPage);
    }

    private void navSearch_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
    {
        this.pnlShellHost.DockControl(this.searchPage);
    }

    private void navEnrollment_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
    {
        this.pnlShellHost.DockControl(this.enrollmentPage);
    }

      

DockControl () code looks like this ->

        public static void DockControl(this Control control, UserControl userControl)
    {
        userControl.Dock = DockStyle.Fill;
        control.Controls.Clear();
        control.Controls.Add(userControl);
    }

      

Are there any implications for this approach? Is this just a stupid plan?

I'm one of those programmers who had to learn how to run before walking, so I have a tendency to fall on my face!

There will be about 30 custom controls throughout.

Any understanding is appreciated and appreciated!

+2


source to share


1 answer


IMO, it's not a bad idea to embed custom controls. In fact, this is exactly what they are for. Since every control inherits from the same base class, you can construct a tree structure of controls using the Composite pattern . This will allow you to create almost anything you would like.

If you are thinking of a basic web page, this is actually what you are doing anyway: placing one element in another or embedding it. You can have multiple divs in other divs, etc. This is essentially what you do when you embed custom controls, when the user controls the rendering of the main HTML.

Hope it helps.



EDIT: To address the issues in your comment ... I don't think you will have a problem in terms of data entry. The reason is that you are using different custom controls for access control and access control. I am assuming that you are overriding the OnLoad event in each of these user controls? What's happening on the downside is that Search OnLoad will be clicked if the search control is loaded, and the OnLoad entry will be enabled if it was loaded.

Because of the polymorphism of custom controls, you can process the data for these controls separately.

+3


source







All Articles