- Shopping Bag ( 0 items )
Ships from: Zephyrhills, FL
Usually ships in 1-2 business days
Ships from: Murphy, TX
Usually ships in 1-2 business days
Microsoft Visual Basic .NET provides the productivity features developers need to rapidly create enterprise-critical web applications. In Visual Basic .NET and the .NET Platform: An Advanced Guide, author Andrew Troelsen shows experienced developers how to use VB .NET for developing virtually every possible kind of .NET application. From Windows-based to web-based applications, ADO .NET, XML Web services, and object-oriented language features, it's all here. There are detailed discussions of every aspect of .NET development and useful examples with no toy code.
Troelsen starts with a brief philosophy of the VB .NET language and then quickly moves to key technical and architectural issues for .NET developers. Not only is there extensive coverage of the .NET Framework, but Troelsen also describes the object-oriented features of VB .NET including inheritance and interface-based programming techniques. Youll also learn how to use VB .NET for object serialization, how to access data with ADO.NET, and how to build (and interact with) .NET Web Services, and how to access legacy COM applications.
Written in the same five-star style as Troelson's previous two books, Developer's Workshop to COM and ATL 3.0 and C# and the .NET Platform, this is the comprehensive book on using VB .NET to build .NET applications that you've been waiting for!
Learn from the author! Check out Andrew's workshop schedule at http://www.intertech-inc.com/courses/CourseDetails.asp?ID=99075&LOC.
This chapter introduces you to the System.Windows.Forms namespace. Here, you learn the details of building a highly stylized main window (using a custom Form-derived type). In the process, you learn about a number of window-related classes, including Application, MenuItem, ToolBar, and StatusBar. This chapter also examines how to capture and respond to user input (i.e., handling mouse and keyboard events) within the context of a GUI environment. As you will quickly discover, Windows Forms directly exposes much more code (and with that code, much more power) than VB 6.0 GUI development.
This chapter also illustrates a more exotic Windows Forms example that stores user preferences in the system registry (using .NET types) and interacts with the Windows 2000 Event Log. Finally, the chapter wraps up by examining the construction of a basic MDI application. The information presented here prepares you for the material presented in Chapters 10 and 11 (GDI+ and programming with Windows Forms controls). Once you complete these chapters, you are in a perfect position to build sophisticated user interfaces using the .NET Framework and VB .NET.
Web Forms, on the other hand, is a GUI toolkit used during ASP.NET development. The bulk of the Web Forms types are contained in the System.Web.UI and System.Web.UI.WebControls namespaces. Using these types, you are able to build browser-independent front ends based on various industry standards (HTML, HTTP, and so forth). You examine ASP.NET (as well as the related topic of Web services) in Chapters 15 and 16. This chapter focuses on building traditional desktop applications using the Windows Forms namespace.
As a relevant side note, it is worth pointing out that while Windows Forms and Web Forms contain a number of identically named types (e.g., Button and CheckBox) with similar members (e.g., BackColor and Text), they do not share a common implementation and cannot be treated identically. Nevertheless, as you become comfortable with the Windows Forms namespace, you should find the process of learning Web Forms far more palatable.
Visual Studio .NET supplies a number of great wizards, starter templates, and configuration tools that make working with Windows Forms extremely simple. The only downside of wizard-generated code is that if you do not understand exactly what the code is doing on your behalf, you have a much tougher time fully understanding the underlying .NET types and the richness of the Windows Forms namespace. To ensure you do not become a victim of wizard code paralysis, write as much "wizard-free" code as possible and make use of the integrated tools where appropriate.
When you build a main window by hand, you need to use the Form and Application types (at a minimum), both of which are contained in the System.Windows.Forms.dll assembly. A Windows Forms application also needs to reference System.dll given that some Windows Forms types make use of types in the System.dll assembly. Add references to these assemblies now using the Add Reference dialog box (see Figure 9-2).
1. Derive a new class from System.Windows.Forms.Form.
2. Configure the application's shared Main() method to call Application.Run(), passing an instance of your new Form-derived class as an argument.
With these steps in mind, update your empty class definition as follows:
' Need to import the Windows Forms namespace.. Imports System.Windows.Forms Public Class MainWindow Inherits Form ' Derive from Form.. Public Shared Sub Main() ' Launch the window!! Application.Run(New MainWindow()) End Sub End Class
Figure 9-3 shows a test run.
Now you have a minimizable, maximizable, resizable, and closable main window (with a default system-supplied icon to boot). Granted, your MainWindow does not do too much at this point. However, you build Forms with enhanced functionality as you move through the chapter.
SOURCE CODE You can find the MyRawWindow application under the Chap-ter 9 subdirectory.
When you click OK, you find that you are automatically given a new class derived from System.Windows.Forms.Form and have references set to each required assembly (as well as some additional assemblies). Notice, however, that you do not directly see a Main() method calling the shared Application.Run() method. This is because the initial Form in a Windows Application is con-figured (by default) to behave as the startup object (which can be confirmed by viewing the Project Properties window). Given that the main Form is the bootstrapper of the entire executable, Application.Run() is called automatically on your behalf.
Much like VB 6.0, Windows Forms applications offer a design-time template that you can use to assemble the user interface of your Form (see Figure 9-5). Understand that as you update this design-time template, you are indirectly adding code to the associated Form-derived class (named Form1.vb by default). This is quite a change from VB 6.0, where the changes you made to a GUI type with the properties window were never realized directly in the code window (although similar information was stored in the corresponding VB 6.0 *.frm file).
Using the Solution Explorer window, you are able to alternate between this design-time template and the underlying VB .NET code. To view the code that represents your current design, simply right-click the *.vb file and select View Code, as shown in Figure 9-6.
You can also open the code window by double-clicking anywhere on the design-time Form; however, this has the (possibly undesirable) effect of writing an event handler for the Form's Load event (more on GUI event processing later in this chapter). In any case, once you open the code window, you see a class looking very much like the following (note that the "Windows Form Designer generated code" region has been fully expanded)...