I have a form and from this I call
dialogPrintDiet.ShowDialog()
which launchs my dialog. I need to pass a string value and need the easiest way to do this in VB.NET
Thnaks
I have a form and from this I call
dialogPrintDiet.ShowDialog()
which launchs my dialog. I need to pass a string value and need the easiest way to do this in VB.NET
Thnaks
You can either add a property to the form or you can add a parameter to your form's constructor.
An example of the first method would look like (where Message is the name of the property)
frm.Message = "Some text"
An example of the second method would look like
Dim frm As New SampleForm ( "Some text" )
Your form code would be something like
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
3 options: You can create a custom constructor for the dialog and pass it in.
Or add a string property and set it between constructing the dialog and showing it.
Or you can overload the ShowDialog method in your dialog class with one that takes a string argument and in there call to the base ShowDialog().
Try properties, for example setting some text boxes in your dialog:
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