Close form a from form b

  • Thread starter Thread starter Guest
  • Start date Start date
Chris said:
How can I close one form (formA), from an event on another form (formB)?

Make a reference to your instance of 'FormA' available to your instance of
'FormB' and call the 'Close' method of your instance of 'FormA'.
 
Thanks Herfried,

Do you a sample of how to do this, I tried but the IDE is telling me that
FormA is a type and cannot be used in an expression.

Thnaks again,
Chris
 
You must have an *instance* of the form. Inside your FormB class, add
a variable of type FormA then overload the constructor of FormB to take
an instance of FormA. Similar to this (pseudocode):

'In FormB

Private MyFormAReference As FormA

Public Sub New(frm As FormA)
MyFormAReference = frm
End Sub



'In FormA somewhere, pass in a reference to Form A:

'Me refers to FormA
Dim MyFormB As New FormB(Me)


'Then later in FormB, you can close FormA like this:

MyFormAReference.Close



Hope this helps a little
 
Back
Top