using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<Button> buttons = null;
List<string> values = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
buttons = new List<Button>();
buttons.Add(button1);
buttons.Add(button2);
buttons.Add(button3);
buttons.Add(button4);
buttons.Add(button5);
values = new List<string>();
values.Add("A");
values.Add("B");
values.Add("C");
values.Add("D");
values.Add("E");
// temp list of boxes
List<TextBox> boxes = new List<TextBox>();
boxes.Add(textBox1);
boxes.Add(textBox2);
boxes.Add(textBox3);
boxes.Add(textBox4);
boxes.Add(textBox5);
foreach (Button button in buttons)
{
button.Click += new EventHandler(button_Click);
}
foreach (TextBox textBox in boxes)
{
textBox.Click += new EventHandler(textBox_Click);
}
}
void textBox_Click(object sender, EventArgs e)
{
this.ActiveTextBox = (TextBox)sender;
}
void button_Click(object sender, EventArgs e)
{
if (this.ActiveTextBox != null)
{
int index = buttons.IndexOf((Button)sender);
string value = values[index];
this.ActiveTextBox.Text = value;
}
}
private TextBox _activeTextBox = null;
private TextBox ActiveTextBox
{
get { return _activeTextBox; }
set { _activeTextBox = value; }
}
}
}
How do i make this apply to dev buttons ?