 |
| VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 24th, 2005, 09:45 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
opening and closing forms
I realize this is very basic, but somehow I am not quite getting it.
I want to close the main form (aka form1) and have only form2 showing.
To open my existing, designed form2 from form1, I do this under a button click event on form1:
dim newform2 as form 'I've tried *as form2* and it doesn't work either
newform2 = new form2
newform2.show()
Ok, form2 now shows up. Then under a button click event I do this:
Dim newform1 As Form 'I've tried *as form1* and it doesn't work either
newform1 = New Form1
newform1.Close()
To close form1. But alas, nothing happens. Form2 stays just as proud as it can be. What am I missing here. Can you believe I just finished writing an involved application that works well, but I still don't get this?
Mike
|
|

March 24th, 2005, 11:56 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
You are creating a new instance of form 1, then closing that new instance.
You need to close the existing instance of it. You should be able to reference the existing instance of form1 without creating any new objects through which to reference it.
|
|

March 24th, 2005, 02:29 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
me.close() executed from form2 closes both form1 and form2 simultaneously.
Mike
|
|

March 24th, 2005, 03:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Is this what you want? Me.Close should only close both forms if, in your case, Form2 is set as the startup form.
J
|
|

March 24th, 2005, 03:56 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Now we are getting somewhere. I simplified my problem for purposes of this forum. The actual program has 6 forms. Form6 is the splash form. I'm fading out form6 into my form1 which is the main form. So I am calling timer events to gradually, but quickly, decrease opacity. When it is done transitioning, I dispose of the timer and I want to make the startup form, which I assigned as form6, to hide, which I can do, and then be closed out of memory. Me.close() in its many variations of what I have been trying has closed both form6 and form 1. So I tried closing form 6 after form1 has received focus, but I can't seem to do that either. I'm confused. Any help is greatly appreciated. Thanks,
Mike
|
|

March 24th, 2005, 05:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Here is one way of setting a startup form and then I'll tell you what I think might be a better solution for what you want(I already typed all of this so I thought I would throw it in as well).
Create a new module in your project, name it whatever you want, but you need to include within it a "Sub Main()". Within this Sub Main you can instantiate whatever form you want without having an owner window. An example of something like this is Macromedia Fireworks MX where they display only the splash page, finish initializing, then show the main form.
Dim frm as New Form1
frm.ShowDialog()
'note the use of showdialog - display your tooltip from your intellisense to get a description
'if you use Show(), it will briefly display your form and then close it after the Sub() is finished running (usually about 1 second).
Then, in your project properties, set your startup object to "Sub Main".
----------------------------------------
Now for what I think might be more of what you want.
When your Form1 starts up, set Form 6 as a modal dialog box, run its timer event and then close it. Form 1 should still be open.
Either way, hopefully one of the suggestions helps.
J
|
|

April 2nd, 2005, 07:37 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply. I tried it both your suggested ways and it became clear to me that I can't do what I am trying to do which is to have one form under another form and the dissolution of the top form reveals the underlying form and the top form be able to closed out of memory. I was able to do it where it would stay in memory, but not close out. I think what needs to be done requires two threads. So for now, I have to be satisfied with the dissolution of one and the immediate startup of another. That is, until I figure out threads.
|
|
 |