AS A FAIRLY PUBLIC figure in the Windows developer community, Chris often gets asked if he thinks that .NET is going to "take off." He always answers the same way: it''s not a matter of "if," it''s a matter of "when." Microsoft''s .NET Framework has so many benefits that even C++/Win32 veterans find it hard to resist the siren song of a managed development environment. It''s ironic that the temporary dip in the economy has caused folks to avoid anything new just when .NET came along to deliver significant reductions in time to market and cost while simultaneously increasing code quality. The organizations that have already adopted .
NET know that it''s going to have a long and happy life, especially as it gets pushed further and further into Microsoft''s own plans for the future of the Windows platform, both on the server and on the client. The primary server-side technology in .NET is ASP.NET, which provides the infrastructure needed to build Web sites and Web services. ASP.NET gives developers the reach to deploy Web sites to anyone by aiming at the baseline of features offered by the middle-generation Web browsers. To provide the highest level of functionality possible, ASP.NET does most of the work on the server side, leaving the client-side HTML as a thin wrapper to trigger server-side requests for new pages of data.
The server side handles almost everything, from data manipulation to user preferences to the rendering of simple things like menus and toolbars. This model provides the greatest availability across operating systems and browsers. If, on the other hand, your targeted customers are Windows users, an HTML-based experience limits your users to a lowest-common-denominator approach that is unnecessary. In fact, in an attempt to provide a richer client-side experience, many organizations that know they''re targeting Windows users require specific versions of Microsoft''s Internet Explorer (IE) Web browser. As soon as that kind of targeting happens, IE becomes less of a browser and more of an HTML-based application run time. For that purpose, the HTML object model is fairly primitive, often requiring that you do a lot of work to do things that are usually simple (like keeping track of a user''s session state). If you''re targeting Windows users, the .NET Framework gives you a much richer set of objects for building interactive user interfaces.
This brings us to the subject of this book: Windows Forms (WinForms). WinForms is the face of .NET on the client, providing a forms-based development environment meant to embody the best of the UI object models that have come before it. In addition, it has one feature that no Windows based development framework has provided to date: the deployment features of HTML-based Web applications. The ability to combine the richness of Windows applications with the deployment of Web applications signals a completely new world for Windows developers, one that makes us more than happy to give up the mess of unmanaged code. Who Should Read This Book? When writing this book, we had two target audiences in mind. We wanted to provide real-world WinForms coverage for both the programmer who has already programmed in .NET and for the programmer who hasn''t.
Toward that end, we briefly introduce core .NET topics as they come up. However, the .NET Framework itself is a large area that this book doesn''t pretend to cover completely. Instead, when we think more information would be useful, we reference another work that provides the full details. In particular, we find that we''ve referenced Essential .NET , by Don Box, with Chris Sells, a great deal, making it a good companion to this book. In this same category, we also recommend Pragmatic ADO.
NET , by Shawn Wildermuth, Advanced .NET Remoting , by Ingo Rammer, .NET Web Services , by Keith Ballinger, and Applied Microsoft .NET Framework Programming , by Jeffrey Richter. (For more details on these books, see the Bibliography.) Two core .NET topics are of special importance to WinForms programmers, and we cover them in more detail in Appendix B: Delegates and Events and in Appendix C: Serialization Basics. The coverage of delegates and events is particularly important if you''re new to .
NET, although I don''t recommend diving into that topic until you''ve got a WinForms-specific frame of reference (which is provided about one-third of the way through Chapter 1: Hello, Windows Forms). One other note: This book covers none of the standard controls completely. Instead, as each control is interesting in the context of the current topic--such as the DataGrid control in Chapter 13: Data Binding and Data Grids--that control is covered appropriately. Also, Chapter 8: Controls and Chapter 9: Design-Time Integration introduce the broad range of categories of controls that WinForms provides, including the category of nonvisual controls called components in .NET. Finally, to give you a visual to go with all the controls and components and to introduce you to each one''s major functionality, Appendix D: Standard WinForms Components and Controls provides a list of the standard controls and components. We wouldn''t think of wasting your time by attempting to be more thorough than the reference documentation that comes with the .NET Framework SDK and Visual Studio .
NET. Instead, this book focuses on the real-world scenarios that aren''t covered in detail elsewhere. Conventions If you have decided to take the plunge with this book, we''d like to thank you for your faith and express our hope that we live up to it. To aid you in reading the text, we want to let you in on some conventions we''ve used. First and foremost, the wonderful thing about WinForms is how visual it is, and that''s why we use a lot of figures to illustrate its features. Some of those pictures really need to be in color to make the point, so be sure to check the color pages at the center of this book for those color plates. As useful as figures are, we think primarily in code. Code is shown in System.
Console.WriteLine("Hello, WinForms.") Console application activation is also shown in monospace type: C:\>vbc.exe hello.vb When a part of a code snippet or a command line activation is of particular interest, we mark it in bold and often provide a comment: '' Notice the use of the .NET System namespace System.Console.WriteLine("Hello, WinForms.
") When we want to direct your attention to a piece of code even more fully, we replace superfluous code with ellipses: Class MyForm Inherits System.Windows.Forms.Form . '' fields Private Sub MyForm_Load(sender As Object, e As EventArgs) MessageBox.Show("Hello from MyForm") End Sub End Class Furthermore, to make the printed code more readable, we often drop namespaces and protection keywords when they don''t provide additional information: '' Shortened "System.Windows.Forms.
Form" base class Class MyForm Inherits Form . '' fields '' Removed "Private" specifier and "System.ComponentModel" namespace Sub MyForm_Load(sender As Object, e As EventArgs) MessageBox.Show("Hello from MyForm") End Sub End Class Conversely, when showing .NET attributes, we use their full name: _ Class MyCustomType . End Class Some languages, such as C#, let you drop the "Attribute" suffix for convenience, but that makes it hard to pin down the details of the attribute class in the online documentation. Also, we sometimes omit error checking from the printed code for clarity, but we try to leave it in the sample code that comes with this book. In the prose itself, we often put a word or phrase in italics to indicate a new term that we''re about to define.
As an example of this kind of term and its definition, hegemony is a preponderant influence or authority, as well as a potent business practice. Finally, we often mention keyboard shortcuts because we find them convenient. The ones we mention are the default Visual Studio Developer key bindings. If you''re not using those key bindings, you''ll need to map he keyboard shortcuts to your own settings. Contact The up-to-date information for this book, including the source code and the errata, are maintained at http://www.sellsbrothers.com/writing/wfbook. This site also provides a way for you to send feedback to us about the book, both complimentary and less so.
--Chris Sells www.sellsbrothers.com --Justin Gehtland www.relevancellc.com 0321125193P10162003.