0
votes

I have three (3) form namely Form1, Form2 and Form3 with button.

Form1 is my main form, window state as MAXIMIZED and form border style as NONE.

My code from Form1 inside a button click event
   Dim form2 As New Form2
   form2.show()

Form2 is a pup-up form that displays some details. Window state as NORMAL and form border style as FIXED. It is opened using a button in Form1.

My code from Form2 inside a button click event
   Dim form3 As New Form3
   form3.showdialog()

Form3 is another pop-up form but is opened using showdialog(). This form hosts some input. When hitting a button in Form3, it must close Form2 and refresh Form1. Window state as NORMAL and form border style as NONE (hiding X to close the form, it will only use the button to close the form)

My code from Form3 inside a button click event
   me.hide()
   Dim form2 As New Form2
   form2.hide() '<--- not working
   Dim form1 As New Form1
   form1.refresh()  '<--- not working
3

3 Answers

1
votes

I found the answer in making the Form2 close using a Button in Form3

Inside the Form3, in the Button click event

Me.Close()

Dim form2 = Application.OpenForms.OfType(Of Form2)().FirstOrDefault()
If form2 IsNot Nothing Then
    form2.Close()
End If

Dim form1 = Application.OpenForms.OfType(Of Form1)().FirstOrDefault()
If form1 IsNot Nothing Then
    form1.Refresh()
End If

I think the form3.Refresh is working but it is not what I need. I want to call the Form1_Load load event in the Form1. Anyone know how is it done?

1
votes

Okay, in Form1, wire up the Form2Closed() event of your Form2 instance and Refresh() from in there:

' ... in Form1 ...

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim form2 As New Form2
    AddHandler form2.FormClosed, AddressOf form2_FormClosed
    form2.Show()
End Sub

Private Sub form2_FormClosed(sender As Object, e As FormClosedEventArgs)
    Me.Refresh()
End Sub

In Form2, you'd simply do:

' ... in Form2 ...

Dim form3 As New Form3
form3.ShowDialog() ' code stops here until form3 is dismissed
Me.Close()
0
votes

You say that those lines of code are not working but they are working. They are doing exactly what they are supposed to do. Take the first example:

Dim form2 As New Form2
form2.hide()

That code says "create a new Form2 object and hide it". Is that NEW Form2 shown? No it's not, so it's working. Your expectation seems to be that telling that NEW Form2 object to be hidden is magically going to hide the EXISTING Form2 object. It's not. If you want to hide that EXISTING Form2 object then you have to call Hide on that object, not on a new one.