We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Events are an integral part of the Windows operating system, as a matter of fact, once your program is loaded and begin to run this be a word or an application you write or anything. Once that program has loaded and begun to run, it is totally event driven. It's usually not doing anything except for events, now let's get a definition of an event here. An event is an action that occurs based on other actions. Best example of this is click event. When we go open an application and click on a button, we want that to create a situation where the program realizes that an event just took place, somebody clicked on a button. And we want to take that information and based on which button they clicked, we want to take certain actions. We may want to show on message box, or open up another portion of the program. We also have events like mouse down, I'm not going to go through all the events here but same thing, whenever this user pushes down that mouse button, we're going to say - ooh, that's an event. And when that happens, we want to take certain action. Events have grown up a lot like everything else in Visual Basic .NET, and it's introducing a lot of new concepts to events, and you are really going to like these things. First of all we get the handles keyword, and if you remember in VB6, the event handler was tied to the event based on the name. For example on a command button it was tied to the name of the command button. And after you set up your event handler, if you change the name of the command button, you had to go change it on event handler, it wasn't very dynamic. That handles keyword lets us care of that and I'll demonstrate that to you later. Delegates - delegates have always been there, they have been in the background with events. All events in Visual Basic are handled by delegates. But again this is a background issue. Just like you saw on the previous set of videos, we can now use delegates as programming objects very easily, and these thing are quite powerful so do understand that delegates are what's happening in the background in these things. Now, they have also introduced the add handler/remove handler. And you'll really like this one because I can now set up a separate class to handle my events, I never have to use the with events keyword, if you know what I am talking about here, and I can just simply add handlers and remove - it will end up in my code. I'll show you that a little bit later on. Let's start off, let's take a look at events in Visual Basic6 and this is how we handled them there. I just want to refresh your memory because if you are an old VB6'er, this is the best way to figure this out. To see the differences. If you remember in Visual Basic6, we created classes by putting code in a class module, and then saving that module and compiling it; so that's what we've done here. You'll notice in Visual Basic 6 we'd have a - Public Event Test() - in our class and this is declaring the event. It's saying I want to have an event called test. And then we would tell it that whenever somebody calls this particular method from this object, that gets instantiated from the class; whenever this method gets called raise that test event. And that is simply saying send out the information, send out information out to the object for whoever is listening that an event just happed, the test event was just raised. Now over an object; now if you remember in VB6 we used forms. And we had a form extension on the form but over on that side, when we created an instance of this object, right here, notice we used the 'with' events keyword and we say - Private With Events x As TheEvent. Then on a separate line, we had to say set X equals to the new event. And this crew instantiated an object off of this class; now then, let's say we had a command button on this particular form and when people click it we want to fire this event. OK and so what we would do is on the click, we would call the x fire event and this would reach over into here. And it would run this, it would raise the event test. And then we had to tell what this, what to be listening for over here. And this would be listening, and notice we would create a sub we would call it X. This is the name of the object that was instantiated and then we'd call it test because that's the name of the event; and then we'd put our code here this is the way this thing was handled. Now there are lots of problems with this, this was not dynamic, not easy to manipulate, it was not easy to change; and in the next video we are going to talk about how this changed in VB .NET. It's very similar with just a couple of differences, but boy do these differences really make life easier for the developer.
| Course: | Microsoft Visual Basic .NET |
| Author: | Mark Long |
| SKU: | 33433 |
| ISBN: | 1932072349 |
| Release Date: | 2003-05-27 |
| Duration: | 6 hrs / 87 lessons |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |