Exploring Existing Delegate Types

You will encounter several existing delegates as you continue learning more about VB .NET. It is important to keep in mind that these delegate types are constrained by the procedure signatures used to define them. Determine the signature and you will know the kind of data passed when the delegate is invoked. You can easily rely on the help system to provide you this information on a case-by-case basis.

Rather than try to provide you with a comprehensive list, I will mention two very common delegates here briefly . The first is EventHandler , and the second is PaintEventHandler .

Both EventHandler and PaintEventHandler have a first argument in common, sender , defined as an Object type. The sender argument is usually the control that invoked the delegate. The second argument for EventHandler is a System.EventArgs parameter, and for PaintEventHandler it is System.Windows.Forms.PaintEventArgs .

NOTE

Etymology is the study of languages. If you have worked with more than one programming language, you have implicitly studied languages. Computer languages, like spoken languages, evolve rather than spring up from nowhere. Visual Basic .NET is an evolution of Visual Basic with influences from Anders Hejlsberg. Hejlsberg mixed in aspects of Object Pascal (available under the product name Delphi). The ways event handling and delegates work have evolved from the Delphi support for procedural types; the sender argument is commonly found in Delphi event handlers.

EventArgs is really a placeholder in anticipation of event handler delegates that may need more information, like Paint events. PaintEventArgs contains an instance of the Graphics object that represents the painting surface of the control that raised the event. (Delphi programmers know the painting surface as the Canvas , and most Windows programmers know that the painting surface is referred to as a Device Context , or DC.)

By handling the Paint event you can get an instance of a control's Graphics object and perform custom painting when the control needs to be painted . The Shape classes demonstrate custom painting. Refer to Chapter 2 for examples that demonstrate the Paint event handler.



Visual Basic. NET Power Coding
Visual Basic(R) .NET Power Coding
ISBN: 0672324075
EAN: 2147483647
Year: 2005
Pages: 215
Authors: Paul Kimmel

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net