title: C# pass a string on an onClick event of a button
body: <p>Ok, I am not sure how to do this as I am trying to teach myself C# and create a program for work at the same time.</p>
  
  <p>I have a List of IP addresss:</p>
  
  <pre><code>List&lt;IPAddress&gt; addresses
  </code></pre>
  
  <p>I have a group of buttons being created for these ip addresses dynamically on the fly once the list is submitted to the form.</p>
  
  <p>I want to pass a string of text associated to the button (the IPAddress) to the onclick event.</p>
  
  <pre><code>Button b = new Button();
  b.Text = "Router\n\r" + String.Format("{0}.{1}.{2}.126", ba[0], ba[1], ba[2]);
  b.Dock = DockStyle.Fill;
  b.Click += btnRouter_Click;
  b.Size = new System.Drawing.Size(150, 50);
  tlp.Controls.Add(b, 1, 0);
  </code></pre>
  
  <p>When the button is clicked I want it to launch a command line argument to call putty.exe and go out to a version of the IP address that it was passed when this button was dynamically created, namely the x.x.x.126 address.</p>
  
  <p>My onClick Stub right now is:</p>
  
  <pre><code>private void btnRouter_Click(Object sender, EventArgs e)
  {
      MessageBox.Show("You clicked the Router button!");
  }
  </code></pre>
  
  <p>what I would like is something like:</p>
  
  <pre><code>private void btnRouter_Click(Object sender, EventArgs e)
  {
      myProcess.StartInfo.FileName = "Putty.exe";
      myProcess.StartInfo.Arguments= "xxx.xxx.xx.126"
      Process.Start(myProcess.StartInfo)
  }
  </code></pre>
  
  <p>Only I don't know how to get that string to the button onclick event since it isn't passes by Object or EventArgs.</p>