【问题标题】:product of two multiline textboxes and display it also to another multiline textbox两个多行文本框的乘积并将其显示到另一个多行文本框
【发布时间】:2022-01-03 16:35:33
【问题描述】:

我想知道如何执行计算,例如两个多行文本框的乘法,它的乘积也将显示在多行文本框中。 请看下面的设计

enter image description here

【问题讨论】:

  • 在换行符上拆分您的输入,遍历数组并将左侧数组的解析十进制值乘以右侧数组,将最终数量放入字符串列表中。然后用换行符加入字符串列表并将其放入第三个文本框中。
  • 除非您有一个项目范围可以这样做,否则您应该尝试使用DataGridView 控件。

标签: c# visual-studio textbox multiplication multiline


【解决方案1】:

如果你想得到两个多行文本框的乘法并在一个多行文本框中显示结果,可以使用如下代码:

private void textBox2_LostFocus(object sender, EventArgs e)
    {
        float a, b;
        for (int i = 0; i < textBox1.Lines.Length ; i++)
        {

            float.TryParse(textBox1.Lines[i], out a);
            float.TryParse(textBox2.Lines[i], out b);
            textBox3.AppendText((a * b).ToString()+ Environment.NewLine);
        }
    }

而且你必须在 Form1.Designer.cs 文件中添加一个 EventHandler:

        // 
        // textBox2
        // 
        this.textBox2.Location = new System.Drawing.Point(312, 110);
        this.textBox2.Multiline = true;
        this.textBox2.Name = "textBox2";
        this.textBox2.Size = new System.Drawing.Size(100, 167);
        this.textBox2.TabIndex = 4;
        this.textBox2.LostFocus += new System.EventHandler(this.textBox2_LostFocus);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 2018-08-13
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    相关资源
    最近更新 更多