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

I just can't, I assume something is not included, but what?

enter image description here

+6
source share
2 answers

Go to your β€œMy project” node in the decision tree. Click this button:

enter image description here

This 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 

After that you should have (MyApplication Events) in the left ComboBox in the code editor and a list of events in the correct ComboBox.

Note. You may need to delete the empty file that you already have after creating it.

+5
source

I think the problem is that you just created a .vb file without linking it to something that actually has events. Based on the picture, I think you want to handle events in your frmInvoice.vb in ApplicationEvents.vb. If this is the intention, then you must specify the class definition in the frmInvoice file using Partial and create an identically named class in ApplicationEvents.vb (also preceded by a partial). The partial keyword allows you to distribute classes across files. The implementation is as follows:

 '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 do not care about this approach and prefer to use regions in one file.

#region "Events"

+1
source

Source: https://habr.com/ru/post/902978/


All Articles