Q:

Transmission of data to the handler

I have Form1 with Form1.cs file, which calls method in Helpers.cs. This method takes as an argument an instance that caused the form, then create a button and textbox and assigns a handler to button. How to transmit textbox text value to handler method when button handler starts ?Helpers.cs have this method:
       public static void startpage(Form form)
    {
        try
        {
            var Tip = new Label() { Text = "Input instance name",
                Location = new Point(50, 50), AutoSize = true };

            var StartConnection = new LinkLabel() { Text = "Connect", 
                Location = new Point(50, 100), AutoSize = true};

            var InstanceInput = new TextBox() { Text = "INSTANCENAME", 
                Location = new Point(100, 70), MaxLength = 1000, Width = 200,
            BorderStyle=BorderStyle.FixedSingle};

            StartConnection.Click += new EventHandler(nextpage);

            Helpers.AddControlsOnForm(form,
                new Control[] {Tip,StartConnection,InstanceInput });

        }
        catch(Exception ex) 
        { MessageBox.Show("Error occured. {0}",ex.Message.ToString()); }
    }
      public static void nextpage(Object sender, EventArgs e)
    {
       //I want to work with instance name and form there
    }

A:

The easiest way would be to attach the TextBox instance to the Tag property of the LinkLabel control and access it in the handler:
public static void startpage(Form form)
{
    try
    {
        var Tip = new Label() { Text = "Input instance name",
            Location = new Point(50, 50), AutoSize = true };

        var InstanceInput = new TextBox() { Text = "INSTANCENAME", 
            Location = new Point(100, 70), MaxLength = 1000, Width = 200,
        BorderStyle=BorderStyle.FixedSingle};

        var StartConnection = new LinkLabel() { Text = "Connect", 
            Location = new Point(50, 100), AutoSize = true, Tag = InstanceInput };

        StartConnection.Click += new EventHandler(nextpage);

        Helpers.AddControlsOnForm(form,
            new Control[] {Tip,StartConnection,InstanceInput });

    }
    catch(Exception ex) 
    { MessageBox.Show("Error occured. {0}",ex.Message.ToString()); }
}

public static void nextpage(Object sender, EventArgs e)
{
   var text = ((sender as LinkLabel).Tag as TextBox).Text;
}

In any case you would either have to store the instance somewhere (in this case in the Tag property) or search the form's Controls collection and locate the desired control.

