473,748 Members | 5,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I add an event to code?

If I have a control, for example a CheckedListBox, how do I add and event
to code, for example that a box has been checked by the user?

Thanks
Nov 16 '05 #1
6 1875
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in the
designer. Next, click on the event icon (the flash of lightning) in the
properties window to display the pre-defined events for this control.
Double-click on the name of the desired event to have VS add an event
handler to your code.

VS writes all necessary code (attaching the event handler to the event,
etc.) behind the scenes. You can view this code by expanding the region
'Windows Form Designer generated dode.' All you'll have to do is write the
code you want the event handler to execute. Of course this only works for
pre-defined events. If you want to create your own event, you'll still have
to go through the usual steps of creating a delegate object, defining and
publishing the event, and attaching the event handler(s).

Hope this helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"vbMark" <no@email.com > wrote in message
news:Xn******** *************** *@130.133.1.4.. .
If I have a control, for example a CheckedListBox, how do I add and event
to code, for example that a box has been checked by the user?

Thanks

Nov 16 '05 #2
"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in
news:uj******** ******@TK2MSFTN GP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.

VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).

Hope this helps.

Wow! Excellent help. Thanks!
Nov 16 '05 #3
"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in
news:uj******** ******@TK2MSFTN GP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.

VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).

Hope this helps.


If I've added an event that I don't want what's the best way to delete it?
Nov 16 '05 #4
Selecting you code and pressing the delete key.

Telmo Sampaio

"vbMark" <no@email.com > wrote in message
news:Xn******** *************** *@130.133.1.4.. .
"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in
news:uj******** ******@TK2MSFTN GP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.

VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).

Hope this helps.


If I've added an event that I don't want what's the best way to delete it?

Nov 16 '05 #5
Just deleting the event handler isn't enough. You also need to remove the
line of code that registers the event handler with the event. For example,
to remove the Load event for a form called 'MyForm' you need to delete two
things:

1. private void frmMyForm_Load( object sender, System.EventArg s e) { // some
code } (the event handler)
2. this.Load += new System.EventHan dler(this.frmMy Form_Load);

The former is the event handler itself, the latter is the line of code that
attaches this event handler to the Load event. You'll find this line in the
*Windows Forms Designer generated code* region.

There is an easier way to do this, though. Go back to the control's
properties and open the events, just like you did to add the event. Select
the name of the event handler next to the event in the list. Delete this
method from the event list. This will remove the code. If there was no code
in the event handler, the handler itself will also be deleted from your
code. If you already wrote code, you still have to delete this method
manually, but all other code related to this event is removed automatically
by VS.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"vbMark" <no@email.com > wrote in message
news:Xn******** *************** *@130.133.1.4.. .
"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in
news:uj******** ******@TK2MSFTN GP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.

VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).

Hope this helps.


If I've added an event that I don't want what's the best way to delete it?

Nov 16 '05 #6
oops... this is the C# group... stupid me :)
I will be more careful on the next posts.

Telmo Sampaio

"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in message
news:O8******** ******@TK2MSFTN GP09.phx.gbl...
Just deleting the event handler isn't enough. You also need to remove the
line of code that registers the event handler with the event. For example,
to remove the Load event for a form called 'MyForm' you need to delete two
things:

1. private void frmMyForm_Load( object sender, System.EventArg s e) { // some code } (the event handler)
2. this.Load += new System.EventHan dler(this.frmMy Form_Load);

The former is the event handler itself, the latter is the line of code that attaches this event handler to the Load event. You'll find this line in the *Windows Forms Designer generated code* region.

There is an easier way to do this, though. Go back to the control's
properties and open the events, just like you did to add the event. Select
the name of the event handler next to the event in the list. Delete this
method from the event list. This will remove the code. If there was no code in the event handler, the handler itself will also be deleted from your
code. If you already wrote code, you still have to delete this method
manually, but all other code related to this event is removed automatically by VS.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights. "vbMark" <no@email.com > wrote in message
news:Xn******** *************** *@130.133.1.4.. .
"Kai Brinkmann [MSFT]" <ka******@onlin e.microsoft.com > wrote in
news:uj******** ******@TK2MSFTN GP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.

VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).

Hope this helps.

If I've added an event that I don't want what's the best way to delete

it?

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2887
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
3643
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind page, 2) Breakpoint in the Page_Load, 3) debug the web page and click the submit button, 4) "step into" under debug several times, 5) The debugger does not stop at any of the statements in the click event handler. A breakpoint is needed in each...
7
390
by: Charles Law | last post by:
I may have asked this before, but what is the purpose of both these functions? Is there a time when one should be called over the other? Does one supersede the other, or do they both have their time and place? TIA Charles
13
3518
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the following issues still exist. The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries to get methods from the receiver that match the pattern. For each one...
41
4317
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
9
2471
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
3
5541
by: geskerrett | last post by:
We have been asked to develop and application for a client that is a 'notification" system. We would like to use python, but are struggling to find the right starting point. Any suggestions, tips or sample code would be appreciated. Application outline; Machine A is running a "listener" application that is connected to a another device via the serial post and waits for events. We have not problem working with the serial port, or...
19
4756
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
4
237
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.