HighTechTalks DotNet Forums  

Close form a from form b

Dotnet Framework (WinForms) microsoft.public.dotnet.framework.windowsforms


Discuss Close form a from form b in the Dotnet Framework (WinForms) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Chris
 
Posts: n/a

Default Close form a from form b - 02-09-2005 , 07:13 AM






Hello,

How can I close one form (formA), from an event on another form (formB)?

TIA

Reply With Quote
  #2  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Close form a from form b - 02-09-2005 , 07:17 AM






"Chris" <Chris (AT) discussions (DOT) microsoft.com> schrieb:
Quote:
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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Reply With Quote
  #3  
Old   
Chris
 
Posts: n/a

Default Re: Close form a from form b - 02-09-2005 , 08:53 AM



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



"Herfried K. Wagner [MVP]" wrote:

Quote:
"Chris" <Chris (AT) discussions (DOT) microsoft.com> schrieb:
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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/
V B <URL:http://dotnet.mvps.org/dotnet/faqs/



Reply With Quote
  #4  
Old   
Chris Dunaway
 
Posts: n/a

Default Re: Close form a from form b - 02-09-2005 , 09:01 AM



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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.