Tips and Tricks: I Didn't Know I Could Do That

In the Visual Basic Guided Tour, you learned how to do a number of things—but that was just a small sample of what you can do with Visual Basic 2008. Even so-called Visual Basic experts are constantly learning new tips and tricks. The following are just a few of the lesser-known things that you can do.


If you are using Visual Basic Express, some of the Help links on this page may be unavailable, depending on the options that you chose during installation. For more information, see Troubleshooting Visual Basic Express.

Tired of boring rectangular forms? Want to create a more interesting look for your application? It's easy with Visual Basic 2008—you can create a bitmap image in the shape that you want and use it as a form, adding code so that the form can be moved and closed. For more information, see How to: Create Nonrectangular Windows Forms.

Want to create a form like the Document Explorer you are using right now, with two or more areas that can be resized by the user? The Windows Forms SplitContainer control allows you to do just that, without any code. Just drop a SplitContainer control onto your form, and then add other controls on top of it; the resizing behavior is automatically available when you run the application.

You can also add multiple SplitContainer controls to a form in order to have resizable regions within regions, allowing you to create an application that looks like Microsoft Outlook. For more information, see SplitContainer Control (Windows Forms).

If you are creating a game, you will probably want your program to make sounds in response to various events. The My.Computer.Audio object allows you to do just that, playing wave files that you include in your application, or even playing files directly from the Internet. For more information, see My.Computer.Audio Object.

You have probably noticed that many Windows-based applications keep track of your preferences, such as the way you like your windows arranged, or the toolbars that were displayed the last time you used the application. You can do the same thing in your own programs by creating and using application settings to store information and retrieve it the next time the application is run. For more information, see Application Settings Overview.

Ever wonder how Web pages keep track of a user's name, displaying messages like "Welcome back (insert your name here)"? You can do something similar in your own applications by using the My.User.Name Property property to get the name of the user currently logged on to the computer. For more information, see My.User Object.

Do you have a Visual Basic 6.0 code example that you would like to use in Visual Basic 2008? The Upgrade Visual Basic 6 Code tool can convert Visual Basic 6.0 code and insert it into your Visual Basic 2008 code. If the code can't be fully translated, comments are added with links to Help topics that explain what you need to do to make the code work. For more information, see How to: Upgrade Visual Basic 6.0 Code with the Upgrade Visual Basic 6 Code Dialog Box.

Visual Basic applications can perform multiple tasks at the same time by using a technique called multithreading. Multithreading is a process in which a task executes on a separate thread of execution, improving the performance and responsiveness of your program.

For example, suppose you have a program that downloads a file from the Internet—the download could take a long time, preventing the user from doing other things until the download is finished. By performing the download on a separate thread, the user is free to do other things while the file downloads in the background. For more information, see Threading (C# and Visual Basic).

Visual Basic also has a BackgroundWorker component that makes it easy to perform a task in the background. For more information, see Walkthrough: Implementing a Form That Uses a Background Operation.

XML Documentation allows you to add comments to a class or user control, so that another programmer will understand how to use them. For example, suppose your user control has a property named "Stretch"—the property name doesn't tell you what the property actually does. XML Documentation lets you add a description like "Determines whether the text will stretch to fill the banner"; the description will show up in the Properties window and in IntelliSense. For more information, see Documenting Your Code with XML (Visual Basic).

Any programs you create with Visual Basic 2008 require that the .NET Framework runtime is already installed on any computer on which you want to run the program; some programs may require other files or prerequisites as well. If you share your program by using ClickOnce publishing, you can use a feature called bootstrapping to include these files and automatically install them, if needed. For more information, see How to: Install Prerequisites with a ClickOnce Application.

In this lesson, you learned a few of the things that you can do with Visual Basic 2008. Of course, this was only a small sample—as you go on to use Visual Basic 2008, you will discover many more things that you didn't know you could do.

In the next lesson, you will learn about ways to connect with other users of Visual Basic.

Next lesson: Community Resources: Getting Help from Other Developers