Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ebook) Visual Studio .NET Mastering Visual Basic.pdf
Скачиваний:
120
Добавлен:
17.08.2013
Размер:
15.38 Mб
Скачать

240 Chapter 5 WORKING WITH FORMS

TBox_Enter() and TBox_Leave() subroutines are not event handlers—at least, not before we associate them with an actual control and a specific event. This is done in the same segment of code that sets the properties of the controls we create dynamically at runtime. After adding the control to the Me.Controls collection, call the following statements to connect the new control’s Enter and Leave events to the appropriate handlers:

AddHandler TB.Enter, New System.EventHandler(AddressOf TBox_Enter)

AddHandler TB.Leave, New System.EventHandler(AddressOf TBox_Leave)

Run the DynamicForm application and see how the TextBox controls handle the focus-related events. With a few statements and a couple of subroutines, we were able to create event handlers at runtime, from within our code.

Summary

In this chapter, you learned the most useful and practical techniques for designing forms. The Windows Form Designer that comes with VS.NET is leaps ahead of the equivalent designer of VB6, and it allows you to design truly elaborate interfaces with very little code (in some cases, no code at all). At the very least, you must make sure that the controls on the form will fit nicely when the form is resized at runtime by setting the Anchor and Dock properties accordingly.

Building applications with multiple forms is a bit more involved than it used to be, but not really complicated. In the following chapter, we’re going to discuss in detail the basic components of the user interface, which are the controls—the basic building blocks of the application. If you think forms come with a lot of built-in functionality, wait until you find out the functionality built into the controls.

Copyright ©2002 SYBEX, Inc., Alameda, CA

www.sybex.com