Pass string to Dialog in VB.net

I have a form and I call

dialogPrintDiet.ShowDialog() 

which launches my dialogue. I need to pass a string value and you need the easiest way to do this in VB.NET.

+4
source share
2 answers

Try the properties, for example, set some text fields in the dialog box:

 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 
+2
source

You can either add a property to the form or add your own form constructor.

An example of the first method would look like this: (where Message is the name of the property)

 frm.Message = "Some text" 

An example of the second method will look like

 Dim frm As New SampleForm ( "Some text" ) 

Your form code will look 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 
+2
source

Source: https://habr.com/ru/post/1304995/


All Articles