简体   繁体   English

在 textBox4(来自 tabPage2)中查看值 textBox3(来自 tabPage1)

[英]See value textBox3(from tabPage1) in textBox4(from tabPage2)

I am beginner in Visual Basic and C#.我是 Visual Basic 和 C# 的初学者。 Have this situation in C#. C#中有这种情况。 3 textBox in tabPage1 (textBox1+textBo2=textBox3) and textBox4 in tabPage2. 3 tabPage1 中的 textBox (textBox1+textBo2=textBox3) 和 tabPage2 中的 textBox4。 I want show value from TextBox3 (from TabPage1) in TextBox4 (TabPage2).我想在 TextBox4(TabPage2)中显示来自 TextBox3(来自 TabPage1)的值。 Value from textBox3 = textBox4.来自 textBox3 = textBox4 的值。 Please a code in VB and/or C#.请在 VB 和/或 C# 中提供代码。 Thanks !!!谢谢 !!!

enter image description here在此处输入图像描述

If you use Integer.TryParse you don't have to check for an empty text box.如果您使用Integer.TryParse您不必检查空文本框。 It will check for a valid number and fill the second parameter with the converted value.它将检查有效数字并用转换后的值填充第二个参数。 What you want to remember is the .Text properties are String and you need numbers to do addition.您要记住的是.Text属性是String并且您需要数字来进行加法。 Otherwise, your strings will be concatenated.否则,您的字符串将被连接。

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim t1 As Integer
    Dim t2 As Integer
    Dim total As Integer
    If Integer.TryParse(TextBox1.Text, t1) AndAlso Integer.TryParse(TextBox2.Text, t2) Then
        total = t1 + t2
    Else
        MessageBox.Show("Please enter a valid number in each text box.")
        Exit Sub
    End If
    Form2.Show()
    Form2.TextBox4.Text = total.ToString
End Sub

EDIT OK, you still need some event to trigger the action.编辑好的,你仍然需要一些事件来触发动作。

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim t1 As Integer
    Dim t2 As Integer
    Dim total As Integer
    If Integer.TryParse(TextBox7.Text, t1) AndAlso Integer.TryParse(TextBox8.Text, t2) Then
        total = t1 + t2
    Else
        MessageBox.Show("Please enter a valid number in each text box.")
        Exit Sub
    End If
    TextBox9.Text = total.ToString
    TextBox10.Text = total.ToString
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM