在VB.net中将字符串传递给对话框

在VB.net中将字符串传递给对话框,vb.net,modal-dialog,Vb.net,Modal Dialog,我有一张表格,从这里我打电话给你 dialogPrintDiet.ShowDialog() 启动我的对话。我需要在VB.NET中传递一个字符串值,并需要最简单的方法来完成此操作。您可以向窗体添加属性,也可以向窗体的构造函数添加参数 第一个方法的示例如下(其中Message是属性的名称) 第二种方法的示例如下所示 Dim frm As New SampleForm ( "Some text" ) 您的表单代码类似于 Public Class SampleForm Private someMe

我有一张表格,从这里我打电话给你

dialogPrintDiet.ShowDialog()

启动我的对话。我需要在VB.NET中传递一个字符串值,并需要最简单的方法来完成此操作。

您可以向窗体添加属性,也可以向窗体的构造函数添加参数

第一个方法的示例如下(其中Message是属性的名称)

第二种方法的示例如下所示

Dim frm As New SampleForm ( "Some text" )
您的表单代码类似于

Public Class SampleForm

Private someMessage As String


Public Sub New(ByVal msg As String)
    InitializeComponent()

    If Not (String.IsNullOrEmpty(msg)) Then
        someMessage = msg
    End If
End Sub

Property Message() As String
    Get
        Return someMessage
    End Get
    Set(ByVal Value As String)
        someMessage = Value
    End Set
End Property

End Class

尝试属性,例如在对话框中设置一些文本框:

Property FirstName() As String
    Get
        Return txtFirstName.Text
    End Get
    Set(ByVal Value As String)
        txtFirstName.Text = Value
    End Set
End Property
Property LastName() As String
    Get
        Return txtLastName.Text
    End Get
    Set(ByVal Value As String)
        txtLastName.Text = Value
    End Set
End Property

如何访问对话框中的FirstName。我使用的是myForm.Member,它显示在IntelleSense中,但总是被指定为“nothing”,即使我在调用对话框之前将其设置正确。很抱歉提出这些愚蠢的问题,但我不习惯VB:(
Property FirstName() As String
    Get
        Return txtFirstName.Text
    End Get
    Set(ByVal Value As String)
        txtFirstName.Text = Value
    End Set
End Property
Property LastName() As String
    Get
        Return txtLastName.Text
    End Get
    Set(ByVal Value As String)
        txtLastName.Text = Value
    End Set
End Property