First, use the Button.Tag property to tie them together:
var buncoockie = new System.Windows.Forms.Button();
buncoockie.Name = "btncki" + xllngth;
buncoockie.Text = "cki" + Convert.ToString(sheet1.Cells[xllngth, 2].value);
buncoockie.Size = new Size(100, 20);
buncoockie.Location = new System.Drawing.Point(145, loc);
buncoockie.BackColor = Color.AliceBlue;
buncoockie.Click += Btncki_Click;
var txtcki = new System.Windows.Forms.TextBox();
txtcki.Name = "txtcki" + xllngth;
txtcki.Size = new Size(150, 20);
txtcki.Location = new System.Drawing.Point(245, loc);
buncoockie.Tag = txtcki;
this.Controls.Add(buncoockie);
this.Controls.Add(txtcki);
loc += 20;
Then, in the event handler:
private void Btncki_Click(object sender, EventArgs e)
{
Button buncoockie = sender as Button;
if (buncoockie != null)
{
TextBox txtcki = buncoockie.Tag as TextBox;
if (txtcki != null)
{
string temp = txtcki.text;
...
}
}
}