/*存储改变前的值*/
private string ComboBox1_Beforevalue = String.Empty;
private string TextBox1_Beforevalue = String.Empty;
/*ComboBox1*/
this.ComboBox1.SelectedIndexChanged += new EventHandler(this.ComboBox1_SelectedIndexChanged);
this.ComboBox1.DropDown += new System.EventHandler(this.BeforeValueSet);
/*TextBox1*/
this.TextBox1.TextChanged += new EventHandler(this.TextBox1_SelectedIndexChanged);
this.TextBox1.Validated += new EventHandler(this.BeforeValueSet);
//也可用Enter事件
//this.TextBox1.Enter+= new EventHandler(this.BeforeValueSet);
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void BeforeValueSet(object sender, EventArgs e)
{
//ComboBox
if (sender is ComboBox)
{
ComboBox comboBox = sender as ComboBox;
switch (comboBox.Name)
{
case "ComboBox1":
ComboBox1_Beforevalue = comboBox.Text;
break;
}
}
//TextBox
if (sender is TextBox)
{
TextBox textBox = (TextBox)sender;
switch (textBox.Name)
{
case "TextBox1":
TextBox1_Beforevalue = textBox.Text;
break;
}
}
}
标签:sender,C#,ComboBox,private,TextBox1,ComboBox1,TextBox
From: https://www.cnblogs.com/sumu80/p/17994621