Creating a custom TabPage control in C #

I am creating a small C # Form tab, and I would like to have some common functions on each tab page, in particular, the OK button and error message, as well as space for specific form fields.

Has anyone else done something similar and how did you approach him?

+5
source share
2 answers

This is easy to do without the TabControl / TabPage extension.

Define one UserControl and place on it all the elements you want on each tab.

: TabPage, TabPage: , UserControl.

:

    // form scoped variable to hold a referece to the current UserControl
    private UserControl1 currentUserControl;

    private void Form1_Load(object sender, EventArgs e)
    {
        foreach(TabPage theTabPage in tabControl1.TabPages)
        {
            currentUserControl = new UserControl1();

            theTabPage.Margin = new Padding(0);
            theTabPage.Padding = new Padding(0);

            theTabPage.Controls.Add(currentUserControl);

            currentUserControl.Location = new Point(0,0);

            currentUserControl.Dock = DockStyle.Fill;

            currentUserControl.SendToBack();
        }
    }

, "SendToBack" , "", UserControl "Okay" TextBox , .

+7

:

  • ;
  • TabPage/TabControl
  • UserControl usercontrols, . TabPage.
+2

All Articles