How to pass value from Form1 to Form2

后端 未结 2 709
渐次进展
渐次进展 2020-12-20 10:52

I\'m making a program that generates SQL Server code to use it in my VB.NET program.

I have this first form that contains the connection like you see in picture belo

2条回答
  •  时光说笑
    2020-12-20 11:06

    The simplest way to pass a value from one form to another is to implement the New method on the form you want to pass the value to:

    Form1:

    Public Class Form1
    
        Private Sub btnPass_Click(sender As Object, e As EventArgs) Handles btnPass.Click
    
            Dim form As New Form2(TextBox1.Text)
            form.Show()
    
        End Sub
    
    End Class
    

    Form2:

    Public Class Form2
    
        Public Sub New(ByVal value As String)
    
            ' This call is required by the designer.
            InitializeComponent()
    
            Label1.Text = value
    
        End Sub
    
    End Class
    

    Screenshot:

提交回复
热议问题