.net 更新标签
我需要的是,我的标签在5个文本框上写的内容之间显示一个加法 我尝试在文本框值更改时执行此操作,但由于有5个文本框,因此需要大量重复代码.net 更新标签,.net,visual-studio-2008,textbox,label,updates,.net,Visual Studio 2008,Textbox,Label,Updates,我需要的是,我的标签在5个文本框上写的内容之间显示一个加法 我尝试在文本框值更改时执行此操作,但由于有5个文本框,因此需要大量重复代码 有没有自我更新标签的方法?如何注册?您可以在文本框的TextChanged事件上注册相同的方法: public FooControl() { InitializeComponent(); textBox1.TextChanged += textBoxes_TextChanged;
有没有自我更新标签的方法?如何注册?您可以在文本框的TextChanged事件上注册相同的方法:
public FooControl()
{
InitializeComponent();
textBox1.TextChanged += textBoxes_TextChanged;
textBox2.TextChanged += textBoxes_TextChanged;
textBox3.TextChanged += textBoxes_TextChanged;
textBox4.TextChanged += textBoxes_TextChanged;
textBox5.TextChanged += textBoxes_TextChanged;
}
void textBoxes_TextChanged(object sender, TextChangedEventArgs e)
{
label1.Content = ...
}
或:
var-sumBoxes=新列表{textBox1、textBox2、textBox3、textbox4、textbox5};
ForEach(i=>i.TextChanged+=sumBoxes\u TextChanged);
我想在标签上保留一种格式:label.Text=format(0,“$”,###0.00”),但当我添加$symbol disapear时,如何阻止这种情况发生?
var sumBoxes = new List<TextBox> { textBox1, textBox2, textBox3, textbox4, textbox5 };
sumBoxes.ForEach(i => i.TextChanged += sumBoxes_TextChanged);