Hi Guys!

I have program here which user are able to submit username and can be displayed.Currently I made 2 forms. Form2 is the submit form where the user can type in their username and press the submit button; Form1 has a label in it which displays the username.

the Problem I have now is that I created another button in form1 which enables users to change their username by reopening form2. But the submit button doesn't work,the username is still the same.

Here is what i Have done:

form1 codes

Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Dim frm2 As New Form2()

        If (frm2.ShowDialog = Windows.Forms.DialogResult.OK) Then
            UserNameLabel.Text = frm2.UserNameTextBox.Text'which displays the username onto the label'
        
        End If
        
   Sub End 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form2.Show()'thats my button reopening form2'
    End Sub

form2 codes

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.DialogResult = Windows.Forms.DialogResult.OK


    End Sub

Anyone can give me a little help out in solving this problem?

Thank You!

Try to dispose previous form instance and create a new one. And use ShowDialog instead of Show.

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Dim frm2 As New Form2()

If (frm2.ShowDialog = Windows.Forms.DialogResult.OK) Then
 UserNameLabel.Text = frm2.UserNameTextBox.Text'which displays the username onto the label'
End If
frm2 = Nothing

End Sub

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.