-
April 30th, 2007, 10:49 AM
#1
Button Behaviour
I have a button called "butCancel"
I have an event called "butCancel_Click"
Code:
Private Sub butCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CancelAction()
End Sub
When I click on the button in design mode, I expect it to go to the "butCancel_Click" event
It doesn't go there but rather, it opens up a NEW event called "butCancel_Click_1"
Code:
Private Sub butCancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butCancel.Click
End Sub
Now where is the logic behind this please ?
Both events are in the same section of the form directly under each other and there is only one button in my project called "butCancel"
-
April 30th, 2007, 10:59 AM
#2
Re: Button Behaviour
You need to add "Handles butCancel_Click" at the end of the declaration.
-
April 30th, 2007, 12:09 PM
#3
Re: Button Behaviour
DSJ has it right.. here is why...
In VB6 the Sub name was subject to the controls name .. IE. Clicking Button Click1 will call event Click1_Click...
In .Net you can name the sub anything you like, as long as you assign it to an event.. using
Code:
Handles Object.Event
hence clicking Button Click1 can call a sub named Close_And_Save_Everything_And_Exit simply by defining it
Code:
Private Sub Close_And_Save_Everything_And_Exit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Click1.Click
Gremmy
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
April 30th, 2007, 01:01 PM
#4
Re: Button Behaviour
Further... you can add handlers via code with the AddHandler statement.
-
April 30th, 2007, 11:15 PM
#5
Re: Button Behaviour
There is a slight difference between Event and Event Handler. Event is something that happens when User does something (clicking a button, typing text, etc) in your application.
Event Handler is a method that is used to write implementation of what is going to happen when that particular event is triggered.
In .NET the terminology has become little too easy. You have an Event and an Event Handler. Event Handler can be given any name (not necessarily button1_click, it can be anything like mybutton_was_clicked or newMethod). All you need to make sure is that your code knows which method to call when an event is triggered, which is given by Handles or AddHandler keywords.
Remember Events are actually implemented using Delegates in .NET. So it will be of great help if you learn Delegates also.
-
May 1st, 2007, 09:09 AM
#6
Re: Button Behaviour
Thanks guys !
Welcome to VB.Net school, George !
Grade F
-
May 2nd, 2007, 10:16 AM
#7
Re: Button Behaviour
Originally Posted by George1111
Thanks guys !
Welcome to VB.Net school, George !
Grade F
Lol .. Na... I'd give ya a 'D' grade...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|