Results 1 to 5 of 5

Thread: Sub Main () [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    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.

  2. #2
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    hi...try this one
    in your form1 constructor
    VB Code:
    1. Dim f As Form
    2.     Public Sub New(ByVal f As Form2)
    3.         MyBase.New()
    4.  
    5.         'This call is required by the Windows Form Designer.
    6.         InitializeComponent()
    7.         Me.f = f
    8.         'Add any initialization after the InitializeComponent() call
    9.  
    10.     End Sub
    11. 'in the form1load
    12. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         f.Close()
    14.     End Sub
    make this as startup object
    VB Code:
    1. Module Module1
    2.     Sub main()
    3.         Dim x As New Form2()
    4.         x.Show()
    5.         Application.Run()
    6.     End Sub
    7. End Module
    in your form2
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim f As New Form1(Me)
    3.         f.Show()
    4.     End Sub
    hope it helps...

  3. #3
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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)

  4. #4
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i do this
    VB Code:
    1. 'form1 as startup object
    2.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.       Dim f As New Form2()
    4.       f.ShowDialog()
    5.    End Sub
    6.  
    7. 'form2 has opacity 0
    8. 'set timer1.enabled = true
    9.   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    10.       Me.Opacity += 0.01
    11.       If Me.Opacity = 1 Then
    12.          Timer1.Stop()
    13.          Timer2.Start()
    14.       End If
    15.    End Sub
    16.  
    17.    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    18.       Me.Opacity -= 0.01
    19.       If Me.Opacity = 0 Then
    20.          Close()
    21.       End If
    22.    End Sub
    i hope i don't provide the wrong code.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Just to make you spoilt for choice:

    In the module

    VB Code:
    1. Dim frm2 As New Form2
    2. Dim frm1 As New Form1
    3.  
    4. Public Sub Main()
    5.   frm2.ShowDialog
    6.   frm1.ShowDialog
    7. 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
  •  



Click Here to Expand Forum to Full Width