|
-
Jun 23rd, 2004, 09:33 PM
#1
Thread Starter
Lively Member
Sub Main () [Resolved]
This is in part two of my other post for an opinion on using a panel for a splash screen. I opted to not use the panel but I tried adding a Form2 to use instead.
Form1 is my main program, I have added a Form2 and placed this code below in it. I have changed the startup object to Form2 and I can get it to load before Form1 correctly so I can use Form2 as my splash screen.
Code:
Public Class Form2
Inherits System.Windows.Forms.Form
+ Windows Form Designer Generated Code
<STAThread()> Shared Sub Main()
Dim frm1 As Form1
frm1 = New Form1()
Application.Run(frm1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close
End Sub
My trouble is that when I push the button on Form2 to close it and show Form1 "My main program" it closes the Form2 but doesn't bring up my Form1 "main program" as it should.
Any other thoughts on what's wrong? Knowing me it's something simple or just my lack of knowledge.
P. S. Pirate, I liked your splash screen but for some reason it didn't work when I tried to impliment it with my program.
Last edited by teamdad; Jun 25th, 2004 at 08:51 PM.
-
Jun 23rd, 2004, 10:04 PM
#2
Registered User
hi...try this one
in your form1 constructor
VB Code:
Dim f As Form
Public Sub New(ByVal f As Form2)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Me.f = f
'Add any initialization after the InitializeComponent() call
End Sub
'in the form1load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
f.Close()
End Sub
make this as startup object
VB Code:
Module Module1
Sub main()
Dim x As New Form2()
x.Show()
Application.Run()
End Sub
End Module
in your form2
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form1(Me)
f.Show()
End Sub
hope it helps...
-
Jun 24th, 2004, 03:42 AM
#3
Hyperactive Member
This a way, very easy, but your Form2 (the splash) is not destroyed when you click its button. It's only hidden:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f1 As New Form1
Me.Hide()
f1.ShowDialog()
Me.Close()
End Sub
But the right way is this, I think:
Code:
Module Module1
Sub Main()
Dim F2 As New Form2
Dim F1 As New Form1
Application.Run(F2)
Application.Run(F1)
End
End Sub
End Module
To use the second one you have to set the startup object to sub main, then add a module to project (default name should be Module1 as mine), and then add the sub main to it, exactly it's showed in the example. In this way, when you will close F2 (with Me.close, for example, or with the X in the high-right corner), F1 will be displayed
Good job
Live long and prosper (Mr. Spock)
-
Jun 24th, 2004, 04:16 AM
#4
Fanatic Member
i do this
VB Code:
'form1 as startup object
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim f As New Form2()
f.ShowDialog()
End Sub
'form2 has opacity 0
'set timer1.enabled = true
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Opacity += 0.01
If Me.Opacity = 1 Then
Timer1.Stop()
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Me.Opacity -= 0.01
If Me.Opacity = 0 Then
Close()
End If
End Sub
i hope i don't provide the wrong code.
-
Jun 24th, 2004, 04:59 PM
#5
PowerPoster
Hi,
Just to make you spoilt for choice:
In the module
VB Code:
Dim frm2 As New Form2
Dim frm1 As New Form1
Public Sub Main()
frm2.ShowDialog
frm1.ShowDialog
End Sub
You can use this format to open as many forms one at a time as you wish, but normally you will want a master form to remain open.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|