I'm trying to pass a string from form1 to form2. The string will change dynamically change as it receive inputs in form1. I've tried some example on passing by property and passing by constructors. But, I can't read the string in the second form. Any pointers? Thanks.
01) you could use a public variable in a module file
02) You can pass it thru the constructor of the new form
03) You can create public properties in the new form and pass them thru that
04) You can access the data directly from the form1's controls
You should avoid accessing the value directly, its bad practice (encapsulation).
You should create a private variable in Form2 and change its value through a public property:
Private _myProperty As String
Public Property MyProperty() As String
Protected Set(ByVal value As String)
_myProperty = value
'inside a method on Form1:
Dim myForm As New Form2
myForm.MyProperty = "text to pass to form2"
Encapsulation is one of the key elements of Object Oriented Design, as such, you should avoid exposing internal variables and controls directly.
Just my 2 cents :)
Thanks for helping. I've manged to get it right with the hints provided.
I've used Ryshad codes, but i ran into trouble of Protected. Well, it's at best to embrace OO, but sometimes it makes life difficult when it comes to mini application like what i'm doing. ;p
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...