How to pass value of a textbox from one form to another form

前端 未结 6 1695
广开言路
广开言路 2021-01-21 09:06

If I have a value stored into a textbox of form1 and I have to pass that value into an another textbox of another form2. What is the method to do this passing values from one fo

6条回答
  •  自闭症患者
    2021-01-21 09:40

    There are a no. of ways.

    1.Using TextChanged event.

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            Form2.TextBox1.Text = TextBox1.Text
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Form2.Show()
        End Sub
    
    1. Using Click event:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Form2.TextBox1.Text = TextBox1.Text
        End Sub
    
    1. Using LostFocus Event:
        Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
            Form2.TextBox1.Text = TextBox1.Text
        End Sub
    

    Similarly you can work with every events.

提交回复
热议问题