Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to register for C# events?

Tags:

c#

events

I am currently transitioning from VB to C# and am having some issues with regards to registering my interest in an event.

When using VB it was simply a case of specifying that a method Handles and event, often this was generated by using the object events list. While I can easily use the Class.event += delegate in C# I am unsure where the best place is to place the code to do this.

Am I best placing it inside of the InitializeComponent() as per the generated code (say if you select the event in the from designer) or should I place it inside the constructor for better readability/maintenance. If inside the constructor, should it be before or after the call to InitializeComponent()?

like image 908
themaninthesuitcase Avatar asked Mar 15 '10 15:03

themaninthesuitcase


People also ask

How does C use registers?

Registers are faster than memory to access, so the variables which are most frequently used in a C program can be put in registers using register keyword. The keyword register hints to compiler that a given variable can be put in a register. It's compiler's choice to put it in a register or not.

What is register value in C?

Register variables tell the compiler to store the variable in CPU register instead of memory. Frequently used variables are kept in registers and they have faster accessibility. We can never get the addresses of these variables. “register” keyword is used to declare the register variables.

Where register variables are stored in C?

Register variables are stored in registers. Static variable is stored in the memory of the data segment. In register variables, CPU itself stores the data and access quickly.

What is register variable C++?

Register variables are similar to automatic variables and exists inside a particular function only. It is supposed to be faster than the local variables. If a program encounters a register variable, it stores the variable in processor's register rather than memory if available.


1 Answers

When you are doing WinForm development (judging from InitializeComponent() function mentioned), usually you assign the handler using Visual Studio. You look up the properties of your control, click on the lightning icon to get the list of all events, find your event, and either double click on it (to create a new handler), or select existing handler from the list. Visual Studio will add the wiring of this in the generated code, so you don't have to worry about it.

like image 94
Grzenio Avatar answered Nov 08 '22 06:11

Grzenio