Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi forum :)

__________________

 

I'm working on an application that consists of form1 and form2. I want the user to open form2 from form1 and then be able to show form1 again.

 

So far I've done this:

 

In form1:

Private form2 as New Form2

Private Sub GoToForm2_click( ...)
form2.ShowDialog()
End Sub

 

and...

 

In form2:

 

Private Sub ButtonClose_click( ...)
Me.Close
End Sub

 

Now, this is a fullscreen game and I don't want the form1 to be opened in the background. I can close it after loading form2 I think, but then I can't re-open it from form2 :eek:

If I have both a "Private form1 as New Form1" and a "Private form2 as New Form2" the application refuses to start.

 

How do you link between forms?

 

_________________

SiMoN.

SiMoN.
  • *Experts*
Posted

Edit the constructor of your second form to accept a form as an instance. So you can manipulate the first from from the second one. Like this:

(this in yur second form)

Dim firstform As Form1 'variable to that will hold the instance
Public Sub New(ByVal formfirst As Form1) 'accept an instance
MyBase.New()
InitializeComponent()
firstform = formfirst 'get the instance to the declared varibel
End SUb

Now you can modify it from your whole class, including hiding and showing it. In your first form you have to declare it like this:

Dim frmTwo As Form2(Me)

:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...