Question

Having a problem linking my form3 back to form2 in windows forms. I want the "back" button to take me back to form 2 but it doesnt do so. I am trying form2.show() but it doesnt work.

My current form3 code:

Public Class Form3

    Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged
        MessageBox.Show("Developer Succsessfully Added to Sprint", "Developer Added")
    End Sub

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        **Form2.Show()**
    End Sub
End Class
Was it helpful?

Solution

What happening is most likely you already closed your form and can't open it again.

Assuming, you have both instances well and alive

In Form2 you should have

me.Hide()
Form3.Show()

And In Form3 you should have

me.Hide()
Form2.Show()

It can be something like this

shared sub Main
    dim f2 as new Form2()
    dim f3 as new Form3()

    f2.Next = f3
    f3.previous = f2

end sub

To link forms you creating properties, Next and Previous And then use that as way to operate the form that should open

In form code do

private sub BtnNext_Click(....).....
    Me.Hide()
    Me.Next.Show()
End Sub

and the same way for the previous. If you have wizard, you could chain all your forms this way. and of course, to accomplish this, minimum, you need an interface that contracts your forms to implement Properties Next and Previous or you can have a base class with implementation of the buttons and properties and then it will all work.

OTHER TIPS

simple code redirect one form1 to form2 Using C#

Form2 f2=new Form2();

f2.show() OR f2.ShowDialog();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top