TouchToolKit for WinForms | ComponentOne
Zoom Panel / Adding Controls at Run Time
In This Topic
    Adding Controls at Run Time
    In This Topic

    To add some controls  to the C1ZoomPanel at runtime, use C1ZoomPanel.BeginAddControls and C1ZoomPanel.EndAddControls methods. You also have to use the InnerControls property of C1ZoomPanel class. instead of the Controls property.

    1. Add C1ZoomPanel to the Form. (C1ZoomPanel1)
    2. Add a Button control to the C1ZoomPanel. (Button1)
    3. Use the following code for Button1.Click event.
    C#
    Copy Code

    private void button1_Click(object sender, EventArgs e)

    {

        c1ZoomPanel1.BeginAddControls();

        Button button2 = new Button();

        c1ZoomPanel1.InnerControls.Add(button2);

        button2.Text = "Button2";

        button2.Visible = true;

        button2.Left = button1.Left;

        button2.Top = button1.Top + button1.Height + 10;

        c1ZoomPanel1.EndAddControls();

    }

    Visual Basic
    Copy Code

    Private Sub Button1_Click(sender As System.Object, e As System.E.ventArgs) Handles Button1.Click

        C1ZoomPanel1.BeginAddControls()

        Dim button2 As New Button()

        C1ZoomPanel1.InnerControls.Add(button2)

        button2.Text = "Button2"

        button2.Visible = True

        button2.Left = Button1.Left

        button2.Top = Button1.Top + Button1.Height + 10

        C1ZoomPanel1.EndAddControls()

    End Sub

    4.Run the project, Zoom-up C1ZoomPanel content and then click Button1.

    5.Confirm Button2 is added in the expected position and size.