Have you ever used Properties before?
Public Properties let you expose data in one Form or Object to other Forms or Objects.
For example, say you want to expose the Text in the Search TextBox in your main Form to your second From. You could create a Public Property (public because if you give anything a Public scope it makes it available to other Objects) that exposes the SearchText:
-
Public Property SearchText As String
-
Get
-
return Me.RichTextBox1.Text 'Or whatever you need to return
-
End Get
-
Set(ByVal value As String)
-
Me.RichTextBox1.Text = value
-
End Set
-
End Property
So now in your second form you can access the data in the main form simply using the Form1.SearchText.
You can use the
PropertyChangedEvent to indicate to all Objects that this property was changed.
Or if you feel like learning things the hard way you can raise an event whenever the text in the search text box changes. You'd create a Custom EventArgs class that can be used to pass event information from the broadcasting class (Form1) to any listening classes (Form2).
For more information on Events please see the article about
how to use events in .NET.
What you'd want to do is create a custom class that inherits from the EventArgs class and provides a property that lets the broadcasting class provide event information and lets the listening class retrieve it:
-
<Serializable()> Public Class TSearchInfoEventArgs
-
Inherits EventArgs
-
Private _searchText As String
-
Public Sub New(ByVal searchText As String)
-
_searchText = searchText
-
End Sub
-
Public Property SearchText As String
-
Get
-
return _searchText
-
End Get
-
Set(ByVal value As String)
-
_searchText = value
-
End Set
-
End Property
-
End Class
Now when the text changes in the search text box you need to raise an event, passing the event the custom EventArgs class that you'll use to relay the text to the:
-
Public Event SearchTextChanged As EventHandler(Of TSearchInfoEventArgs)
-
-
Private Sub RichTextBox1_KeyUp(bla bla bla) Handles RichTextBox1.KeyUp
-
RaiseEvent SearchTextChanged(Me, New TSearchInfoEventArgs(RichTextBox1.Text))
-
End Sub
Or just do some research on Properties and the PropertyChangedEvent :)
-Frinny