Results 1 to 3 of 3

Thread: Help with Events

  1. #1

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681

    Help with Events

    I have my app starting from a Sub Main in a module and want to show a form and have a button click event handled in the module.

    In the module I have:

    VB Code:
    1. Friend WithEvents frmForm1 As frmForm1
    2. Friend WithEvents btnRun As Button
    3.  
    4. Public Sub Main()
    5.         DoSomething()
    6. End Sub
    7.  
    8. Private Sub DoSomething()
    9.  
    10.         frmForm1 = New frmForm1
    11.         btnRun = frmForm1.btnRun
    12.         frmForm1.Show()
    13.        
    14. End Sub
    15.  
    16. Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
    17.  
    18.         MessageBox.Show("Clicked button")
    19.        
    20. End Sub

    What is happening is the form comes up and then closes right away. What am I missing?

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    To emulate the vbModla functionality use ShowDialog e.g.

    VB Code:
    1. frmForm1.ShowDialog()

  3. #3

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Sweet, I knew I was missing something easy

    By the way, is this commonly done? - Sub Main controlling everything in this way?

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