Professional Documents
Culture Documents
Visual Basic Book2
Visual Basic Book2
Introduction
Developer productivity is the mantra for this release of Microsoft Visual Studio. Regardless of the application types you use or the languages you choose, Microsoft has focused its effort on building an integrated development environment (IDE), class library, and language suite that makes it as easy as possible to build and deploy applications. It is obvious to us, the authors of this book, that Microsoft has looked at all aspects of coding including the writing of the code itself, debugging, and deploymentand really examined how it could streamline each of these experiences. The enhancements are far reaching and include changes to the Microsoft Visual Basic .NET language itself, improvements to the IDE, simplification of data access and display, changes that increase developer productivity when constructing professional user interfaces, addition of a significant number of new classes to the framework to reduce the amount of code that you write, and an increase in the power and simplicity of deployment. This book will examine each of these areas in depth. In addition, while this book focuses on building desktop applications, most developers are doing at least some Web development. For this reason, Chapter 6, Building Web Applications, covers some of the most significant changes to ASP.NET. This introduction briefly covers these topics and points you to the specific chapter where you can get more in-depth information. You can read this book from cover to cover or skip to the chapters of most interest to you.
ix
In this example, the customerDictionary can store items only of type Customer. And the lookup is specifically a String value. Because the collection knows what its storing (Customers vs. just Objects), it can provide full Microsoft IntelliSense, as shown in the following figure.
Figure I-1
Introduction
xi
The My Object Another significant enhancement to Visual Basic .NET is a feature simply known as The My Object. This feature provides extremely quick and easy access to powerful functionality. For example, My.Application.Log.WriteEntry will let you write information to a text file, event log, or other destination. My.Computer.Audio.PlaySystemSound will let you play predefined operating system sounds, while My.Computer.Audio.Play will let you play any .wav file. The My Object also gives you default instances for items that are part of your project. For example, you can use My.Forms.MainForm.Show to display a form without first creating an instance of it. New Operators Visual Basic .NET also includes a number of new keywords. IsNot facilitates comparisons with Nothing. In the past, you often had to write If Not X Is Nothing Then. Now this can be written as If X IsNot Nothing Then. Visual Basic .NET also supports operator overloading, generics, and many other advanced programming features. For more on these enhancements, see Chapter 2, Language Enhancements for Visual Basic 2005.
Figure I-2
xii
As you can see, Visual Studio 2005 can either show you all the members of an object or filter the list to show just the most commonly used members, making it easy to find the ConnectionString property, for example. Visual Studio 2005 also further extends familiar Visual Basic code expansions. Youre used to typing in the beginning Function declaration and having the IDE automatically insert the End Function for you. Now this is expanded to such things as property declarations. Typing public property UserName as String and pressing Enter causes the automatic insertion of the following code:
Public Property UserName() As String Get End Get Set(ByVal value As String) End Set End Property
Visual Studio 2005 also puts information at your fingertips when debugging, letting you drill into simple and complex types, without opening and navigating through the Watch window. The following figure shows how a complex type is displayed directly in the code editor.
Figure I-3
One of the single biggest productivity enhancements provided by Visual Basic 6 was EditAnd-Continue. This functionality was a mainstay of the debugging experience and was unfortunately not available in Visual Studio .NET 2002 or 2003. Edit-And-Continue is back, allowing you to fix errors and continue execution without stopping and restarting. IDE Customization and Help System Enhancements Visual Basic developers highly value the ability to customize their development environment and place windows where they will be most useful to them. Visual Studio has always provided this capability, but with Visual Studio 2005, the capability has been significantly enhanced in several key areas. First, Visual Studio 2005 eliminates the I wonder where this window will dock problem, where you think you have a window positioned correctly, but when you let go of it, it either doesnt dock or doesnt dock the way you expected. In Visual Studio 2005, docking is a snap with docking guides, as shown in the following figure.
Introduction
xiii
Figure I-4
You simply drop the window on the appropriate arrow to dock it over, above, to the right of, below, or to the left of another window. No more guessing! Also, all your IDE customizations can be exported and imported. In addition, the Help system has been greatly improved, providing you a better F1 experience, but also letting you access the latest help available online. The help system even hooks into the Code Wise community of Web sites, providing access to such sites as CodeGuru, Net247, and ASP.NET right inside of the IDE. For more information about the significant productivity enhancements provided in Visual Studio 2005, you can go directly to Chapter 3, Visual Studio 2005 Integrated Development Environment.
xiv
Figure I-5
You can see that by default, when the customers table is dropped on to the design surface, it renders it using the new GridView control. You can also have it render as individual fields, and you can determine the type of control thats used for each field. You can also use the DataSet Designer to map methods to stored procedures. This makes calling a stored procedure as easy as the following code:
ds = MyDataSet.GetByCustomerID(customerID)
For more information on using data in Visual Studio 2005, see Chapter 4, Building Datacentric Applications.
Introduction
xv
Figure I-6
You can see that a simple form has been created with two ToolStrip controls. This was literally done in a matter of seconds, but there are actually quite a few things to discuss. First, you can see that the ToolStrip controls support rafting, which means that the user can drag the ToolStrip controls around and arrange them at run time. Second, the top ToolStrip contains the standard icons that you are familiar with. These were added with a single click. If there are any icons that you dont want, you can simply select them and press Delete. The ToolStrip also supports more than just buttons. It can contain text boxes, drop-down lists, labels, and more. Finally, the toolbars look just like the Microsoft Office toolbars, making it easy to build professional-looking applications that your users will natively understand how to use. The menu bar and status bar build on the ToolStrip infrastructure, letting you have a wider variety of controls and capabilities in the menu or status bar. In the toolbox, youll also find a full .NET wrapper around the ActiveX Web browser control, making it simple to add Web functionality to applications. This control can be used to display Web-based help or take users to a page where they can purchase a product. Changes to Existing Controls One of the first things that youll notice when you build forms is snaplines, which make it quick and easy to line up controls as you build the user interface, as shown in the following figure.
xvi
Figure I-7
When dragging controls around the design surface, rather than seeing the traditional grid, you have snaplines that appear and make it simple to perfectly align controls. The snaplines let you align the edges of controls and also recommend appropriate spacing between the controls. The spacing is controlled by a new Margin control property. Many controls also contain new auto-complete properties that let the controls automatically provide suggestions for file names, URLs, custom lists, or other sources. For more on building professional user interfaces, and the new application configuration infrastructure, see Chapter 5, Constructing User Interfaces.
Introduction
xvii
and personalization built in. Membership is a package of functionality that provides common controls for things such as logging in, changing your password, and so on. It also provides the infrastructure to automatically store and retrieve information from a back-end database. Finally, membership gives you APIs to work with a user programmatically. ASP.NET also ships with a number of new controls to address key scenarios. For example, the SiteMapPath control provides built-in breadcrumb functionality, and the SiteMapDataSource can make it easy to build site navigation. Master Pages allow you to define common areas of the page in one place, with only the content area changing. Caching has been improved, and data can now be cached on a per-user basis. For more information on ASP.NET 2.0, see Chapter 6, Building Web Applications.
xviii
known as No-Touch deploymentalso sometimes called href-exes. In this method of deployment, an application executable was simply placed on a Web server. When you browsed to the URL for the application, it would download and run. The result was a full Windows application with the ease of deployment of Web applications. With .NET, even if you needed to create a Windows Installer package, the process of doing so was greatly simplified because you did not have to worry about DLL registration. No Touch deployment was seen by many as an excellent approach for intranet applications. Through a simple portal, you could ensure that users were always running the latest version of the application. With Visual Studio 2005, Microsoft has significantly enhanced the capabilities of applications distributed through the Web. First, the applications can now download and fully install. This capability creates the appropriate Start menu shortcuts, and (more importantly) it lets the application function fully even when youre offline. ClickOnce applications also do not require you to be an administrator to install them (as Windows Installer packages do). Finally, ClickOnce allows you to bootstrap other required software as part of the installation. For example, a ClickOnce application can install MDAC, or even the .NET Framework if needed, as part of the application installation. For more information on ClickOnce, see Chapter 8, Deploying Applications.
Support
Every effort has been made to ensure the accuracy of this book. If you run into a problem, Microsoft Press provides corrections for its books through the following Web site: http://www.microsoft.com/learning/support/. If you have problems, comments, or ideas regarding this book or the companion CD-ROM, please send them to Microsoft Press. Send e-mail to mspinput@microsoft.com Send postal mail to Microsoft Press Attn: Introducing Microsoft Visual Basic 2005 for Developers Editor One Microsoft Way Redmond, WA 98052-6399 Please note that support for the software product itself is not offered through the preceding addresses. For product support, go to http://support.microsoft.com. To connect directly to the Microsoft Knowledge Base and enter a query regarding a question or issue that you have, go to http://support.microsoft.com.