How to close sub-form opened by showDialog()?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

How to close a sub-form opened by showDialog()?

On the main form, I open a new form by using showDialog().
There is a Timer control on the main form, when Timer.Tick raises, the
program closes the sub-form and main form.
But now, the sub-form cannot be closed and the Me.close() rases error.

Private subForm as Form

Private Sub btnM_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnM.Click
Dim frm As New Form2(Me)
subForm = frm
frm.ShowDialog()
End Sub

Private Sub Logout(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If Not subForm Is Nothing Then
subForm.Close()
End If
Me.Close()
End Sub

Thanks in advance.

Regards,
Alan
 
Hi,

What is the error message?
Don't forget you must use Invoke to refresh a control from an other
thread than the one created the control.
In C# :
this.Invoke(new EventHandler(delegate
{
this.Close();
}));


BR

Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)http://www.adeneo.adetelgroup.com/
 
Back
Top