Reputation: 123
I have two forms namely "MainForm" and "SubForm" Now "Mainform" has a button and a textbox. Upon clicking the button, "SubForm" should be opened while MainForm will also remain opened. Now SubForm has a text box and an OK button. User will input the value in the textbox and on clicking OK, SubForm should be closed and MainForm textbox text should be changed to the text which has been entered in SubForm textbox. Thanks in advance
Upvotes: 0
Views: 493
Reputation: 8591
Change the constructor for SubForm
and add a property this way:
Private sValue As String = String.Empty
Public New(myText As String)
SomeText = myText
TextBox1.Text = SomeText
End Sub
Public Property SomeText As String
Get
Return sValue
End Get
Set(value As String)
sValue = value
End Set
End Property
'on OK button click event
SomeValue = TextBox1.Text
Then in MainForm
(on button click):
Using sf As SubForm = new SubForm(Me.InitialText.Text)
Dim dlg As DialogResult = sf.ShowDialog()
If dlg = DialogResult.OK Then
Me.InitialText.Text = sf.SomeText
End If
End Using
Other settings:
SubForm
:
AcceptButton
property - refers to OK
buttonOKButton.DialogResult
= OK
TextBox1
- the name of textbox for user inputMain form
InitialText
- the name of textboxUpvotes: 2