30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

480 Graphical User Interface Concepts: Part 1 Chapter 12<br />

Form Properties and<br />

Events Description / Delegate and Event Arguments<br />

Hide Hides form (does not destroy the form or release its resources).<br />

Show Displays a hidden form.<br />

Common Events (Delegate EventHandler, event arguments EventArgs)<br />

Load Occurs before a form is displayed <strong>to</strong> the user. The handler for this<br />

event is displayed in the edi<strong>to</strong>r when the form is double-clicked in the<br />

<strong>Visual</strong> Studio .<strong>NET</strong> designer.<br />

Fig. 12.4 Common Form properties, methods and events (part 2 of 2).<br />

When we create controls and event handlers, <strong>Visual</strong> Studio .<strong>NET</strong> generates a large<br />

amount of the GUI–related code. Constructing GUIs can be performed graphically, by<br />

dragging and dropping components on<strong>to</strong> the form and setting properties via the Properties<br />

window. In visual programming, the IDE generally maintains GUI-related code and<br />

the programmer writes the necessary event handlers.<br />

12.3 Event-Handling Model<br />

GUIs are event driven—they generate events when a program’s user interacts with the GUI.<br />

Typical interactions include moving the mouse, clicking the mouse, clicking a but<strong>to</strong>n, typing<br />

in a textbox, selecting an item from a menu and closing a window. Event information<br />

is passed <strong>to</strong> event handlers, which are methods that are called as a result of specific events.<br />

For example, consider a form that changes color when a but<strong>to</strong>n is clicked. Clicking the but<strong>to</strong>n<br />

generates an event and passes it <strong>to</strong> the but<strong>to</strong>n’s event handler, causing the event-handler<br />

code <strong>to</strong> change the form’s color.<br />

Events are based on the notion of delegates, which are objects that reference methods<br />

(see Section 10.11). Event delegates are multicast (class MulticastDelegate), which<br />

means that they represent a set of delegates with the same signature. Multicast delegates<br />

enable event calls <strong>to</strong> be sent sequentially <strong>to</strong> all delegates contained within the multicast delegate.<br />

To learn more about delegates, see Chapter 10, Object-Oriented <strong>Program</strong>ming: Polymorphism.<br />

In the event-handling model, delegates act as intermediaries between the objects<br />

creating (raising) events and the methods handling the events (Fig. 12.5).<br />

call calls<br />

Object A generates event E Delegate for event E<br />

Fig. 12.5 Event-handling model using delegates.<br />

Handler 1 for event E<br />

Handler 2 for event E<br />

Handler 3 for event E

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!