Passing variables between windows forms in VS 2010

前端 未结 3 496
你的背包
你的背包 2021-01-14 03:34

I have two forms. Form 1 allows the user to pick an employee from a dropdown combo box. That employee is then passed onto Form 2 where the user enters additional information

3条回答
  •  温柔的废话
    2021-01-14 04:20

    You don't even have to use the InitializeComponent or New functions.

    I have made an example to show how easily this can be done.

    enter image description here

    Clicking "Show Form" results in the below:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub
    

    which is simply used to display the second form.

    By clicking "Pass Data" results in the following code:

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Form2.Label1.Text = TextBox1.Text
    End Sub
    

    As shown above you can pass the data directly from control to control. The same idea can be used with variables too.

提交回复
热议问题