|
-
Feb 24th, 2013, 11:19 AM
#1
Thread Starter
Hyperactive Member
Open Splash Form - Close Splash & Load Form1
Retyped:
Splash screen appears, there is a button to continue. When button is pressed, Splash disappears and Form1 is loaded.
I've used the Splash.hide() to hide the splash, but then I red somewhere that you should close the forms if they're not being used.
So in this instance I have used:
Code:
Form1.Show()
Me.Hide()
Is this the correct sequence to closing the other form. If not can I use this command when the user has finished to close the main form which hopefully closes everything else where I used the .hide.
Last edited by jokerfool; Feb 27th, 2013 at 01:42 PM.
-
Feb 24th, 2013, 11:30 AM
#2
Re: Open new form close current form
When opening a form from another form and closing the called form
lets say form1 and form2
call form2 from form1 , & once the form2 is loaded close the form1 ?
Code:
Private Sub Somebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'' open the form2
Dim f As New Form2
f.Show()
End Sub
''once the form2 is loaded , close the form 1 now
Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form1.Close()
End sub
'' now i am disposing off the form1 object from memory
Code:
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
End Sub
-
Feb 24th, 2013, 11:50 AM
#3
Thread Starter
Hyperactive Member
Re: Open new form close current form
Okay so now you've confused me.
What exactly do I place between the subs?
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
-
Feb 24th, 2013, 11:57 AM
#4
Re: Open new form close current form
i am confused now, in fact what you want to do on click of button1 ? you put that code with in the sub
that's what the code code does here
Code:
Private Sub Somebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'' open the form2
Dim f As New Form2
f.Show()
End Sub
and so on read further a
-
Feb 24th, 2013, 12:08 PM
#5
Thread Starter
Hyperactive Member
Re: Open new form close current form
Nope that doesnt work, original form still there. If I add the other code says error.
-
Feb 24th, 2013, 12:09 PM
#6
Thread Starter
Hyperactive Member
Re: Open new form close current form
Wait, did I do something wrong here?
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f As New Form1
f.Show()
Form9.Close()
Me.Dispose()
End Sub
-
Feb 25th, 2013, 10:01 AM
#7
Re: Open new form close current form
you need to go through all the codes & in which event it is being triggered
( concentrate on the events of which form happening what , code is very easy and straight forward )
what you did here is
''
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f As New Form1
f.Show() ' you have sown the form1 here Presumably from Form9
' fine form1 is opened now you are in form1
' form9 is still open Right ?
' then when it is going to close , i think that's what is your worry
Form9.Close() ' this line supposed to close the form9 , but what happen , you better set a break point here & run the app
Me.Dispose() ' here who is the me , form1 or form9
that's why your last 2 lines of code is being triggered at the form load event of form9
means form9 takes birth & once it takes the birth it closes it's mother , & once the mother closes ( see form closed event )
it disposes off completely
End Sub
-
Feb 26th, 2013, 03:48 PM
#8
Thread Starter
Hyperactive Member
Re: Open new form close current form
Okay need some help still, not quite got it.
Does mean get ready to open Form 1?
And this means once the button is pressed close the current form which is Form 9 then Dispose of it and run Form 1? I think I am still lost somewhere.
-
Feb 26th, 2013, 04:00 PM
#9
Frenzied Member
Re: Open new form close current form
 Originally Posted by jokerfool
Wait, did I do something wrong here?
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f As New Form1
f.Show()
Form9.Close()
Me.Dispose()
End Sub
That's not remotely the code he posted for you...
You are trying to do everything in one event, he showed you how to do it with three events...
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Feb 26th, 2013, 04:09 PM
#10
Thread Starter
Hyperactive Member
Re: Open new form close current form
So are you saying in .NET you cant do everything in one event I have to do it in 3?
-
Feb 26th, 2013, 04:20 PM
#11
Thread Starter
Hyperactive Member
Re: Open new form close current form
Blank Form with 1 button
Code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form9
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(144, 134)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(127, 82)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Form9
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(682, 507)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form9"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form9"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f As New Form1
f.Show()
End Sub
Private Sub Form9_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
End Sub
Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form9.Close()
End Sub
End Class
It surely cant be this hard, I know people dont like giving the answers away and let the user try and try and try and get error after error, dont tell me the answer just explain if you can what I have done wrong im still all new at this, thanks for helping.
-
Feb 26th, 2013, 04:21 PM
#12
Frenzied Member
Re: Open new form close current form
 Originally Posted by jokerfool
So are you saying in .NET you cant do everything in one event I have to do it in 3?
That should be apparent by the fact it isn't working. Events fire based on different actions. Put things in their proper place. The couple extra lines of code aren't going to hurt you to make sure things go into the right events.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Feb 26th, 2013, 04:35 PM
#13
Thread Starter
Hyperactive Member
Re: Open new form close current form
Why create a software application that requires 3 events yet in vb6 I could do it in one event, thats what confuses me, all this seems so complicated just to open a splash, close it and display a form.
-
Feb 26th, 2013, 04:51 PM
#14
Frenzied Member
Re: Open new form close current form
 Originally Posted by jokerfool
Why create a software application that requires 3 events yet in vb6 I could do it in one event, thats what confuses me, all this seems so complicated just to open a splash, close it and display a form.
Stop trying to compare it to VB6 and you will sleep much better at night. Just because you could get away with something doesn't mean you should. That can lead to all sorts of issues down the road when things get more complicated.
Put it this way. Every play pool? Do you still play slop like you did when you were 12, or do you call your shots now?
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Feb 26th, 2013, 06:15 PM
#15
Re: Open new form close current form
 Originally Posted by jokerfool
Why create a software application that requires 3 events yet in vb6 I could do it in one event, thats what confuses me, all this seems so complicated just to open a splash, close it and display a form.
It isn't. But this wasn't the question you asked. You wanted to know how to open a new form from a button and close the form on which the button was clicked. At no point did you suggest that this was a splash scenario. We can't answer questions you don't ask. So describe exactly the sequence of events, including all interaction such as clicks, that you're proposing and we might be able to get there!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Feb 27th, 2013, 01:21 PM
#16
Thread Starter
Hyperactive Member
Re: Open new form close current form
I've edited the first post.
-
Feb 27th, 2013, 01:43 PM
#17
Re: Open Splash Form - Close Splash & Load Form1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|