|
delegate void DelTest(object sender);
class TestClass
{
public void TestMethod(object sender)
{
TextBox txt = (TextBox)sender;
if (String.IsNullOrEmpty(txt.Text))
txt.BackColor = ColorPicker.error;
else
txt.BackColor = ColorPicker.normal;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
TestClass tc = new TestClass();
DelTest test = new DelTest(tc.TestMethod);
test(textBox1);
}
private void Form1_Shown(object sender, EventArgs e)
{
TestClass tc = new TestClass();
DelTest test = new DelTest(tc.TestMethod);
test(textBox1);
}
こんな感じでいかがですか?
|