I have made 2 form in my project. But I want to make the first form to enter an input and as the second form, it can display the output. The problem is, I have enter all the input using the textbox, but the output cannot be displayed in the second form by using the listbox.
Asked
Active
Viewed 4,736 times
3
-
1can you show us the code that doesn't work? – Jeremy Thompson Oct 14 '12 at 04:19
1 Answers
1
You can create a Public Method on your second Form and Call it from your First Form. I created two Forms one with a TextBox and another with a ListBox, if you want anymore detail you will need to give an example of what the problem that you are having is.
Form1
Public Class Form1
Dim frm2 As Form2
Private Sub TextBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim tb As TextBox = CType(sender, TextBox)
If e.KeyChar = vbCr Then
If tb.Text.Length > 0 Then
frm2.ListBoxAdd(tb.Text)
tb.Text = ""
e.Handled = True
End If
End If
End Sub
Public Sub New()
InitializeComponent()
frm2 = New Form2
frm2.Show(Me)
End Sub
End Class
Form2
Public Class Form2
Public Sub ListBoxAdd(data As String)
ListBox1.Items.Add(data)
End Sub
End Class

Mark Hall
- 53,938
- 9
- 94
- 111