Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 更新标签_.net_Visual Studio 2008_Textbox_Label_Updates - Fatal编程技术网

.net 更新标签

.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;

我需要的是,我的标签在5个文本框上写的内容之间显示一个加法

我尝试在文本框值更改时执行此操作,但由于有5个文本框,因此需要大量重复代码


有没有自我更新标签的方法?如何注册?

您可以在文本框的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);