Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't i declare application events in vb.net visual studio 2010?

I just can't, im guessing something's not enabled, but what?

enter image description here

like image 989
Qqbt Avatar asked Dec 03 '11 01:12

Qqbt


2 Answers

Go to your "My Project" node in your solutions tree. Click on this button:

enter image description here

It should result in the following file:

Namespace My

  ' The following events are available for MyApplication:
  ' 
  ' Startup: Raised when the application starts, before the startup form is created.
  ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
  ' UnhandledException: Raised if the application encounters an unhandled exception.
  ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
  ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
  Partial Friend Class MyApplication

  End Class

End Namespace

Once there, you should have the (MyApplication Events) in the left ComboBox in your code editor, and the list of events in the right ComboBox.

Note: You might have to delete the empty file you already have before creating this.

like image 110
LarsTech Avatar answered Nov 15 '22 06:11

LarsTech


I think the problem here is that you simply created a .vb file without relating it to something that actually has events. Based on the picture, I'm thinking you want to handle the events in your frmInvoice.vb in the ApplicationEvents.vb. If this is the intent, then you should preface the class definition in the frmInvoice file with Partial and create an identically named class in the ApplicationEvents.vb (also prefaced with partial). The partial keyword allows you to span classes across files. The implementation looks like this:

'On actual form
    Partial Public Class Form1

    End Class

'On other .vb file
    Partial Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            MsgBox("test")
        End Sub
    End Class

I personally don't care for this approach and prefer using regions within a single file.

#region "Events"

like image 24
UnhandledExcepSean Avatar answered Nov 15 '22 05:11

UnhandledExcepSean