将字符串传递给VB.net中的Dialog

时间:2010-03-24 13:21:53

标签: vb.net modal-dialog

我有一张表格,我打电话给

dialogPrintDiet.ShowDialog()

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

2 个答案:

答案 0 :(得分:2)

您可以向表单添加属性,也可以向表单的构造函数添加参数。

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

frm.Message = "Some text"

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

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

答案 1 :(得分:2)

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

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