简体   繁体   中英

See value textBox3(from tabPage1) in textBox4(from tabPage2)

I am beginner in Visual Basic and C#. Have this situation in C#. 3 textBox in tabPage1 (textBox1+textBo2=textBox3) and textBox4 in tabPage2. I want show value from TextBox3 (from TabPage1) in TextBox4 (TabPage2). Value from textBox3 = textBox4. Please a code in VB and/or C#. Thanks !!!

enter image description here

If you use Integer.TryParse you don't have to check for an empty text box. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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