Chapter 14. Special Programming Techniques

Introduction

The “A” in BASIC—the predecessor of Visual Basic—stands for “all-purpose.” As an heir of that original programming language, Visual Basic has maintained the standard of being an all-purpose language, a language that is generic enough to handle a vast set of different programming needs. That has never been truer than with Visual Basic 2005.

The recipes included in this chapter cover a wide range of topics, from basic application management to credit card verification. The key is that you can do all these varied tasks quite easily in Visual Basic.

14.1. Preventing Multiple Instances of a Running Application

Problem

You don’t want the active user to run more than one copy of an application at any one time.

Solution

Sample code folder: Chapter 14\SingleInstanceOnly

Capture attempts to start up secondary instances of an application through an application-wide event handler. This event handler, new to Visual Basic 2005 and available only to Windows Forms applications using the Application Framework, triggers in the primary instance whenever the user tries to start a secondary instance.

Discussion

Create a new Windows Forms application in Visual Studio. The Application Framework is enabled by default; you can confirm this by checking the “Enable application framework” field on the Application tab of the Project Properties window, shown in Figure 14-1.

Figure 14-1. Make sure the “Enable application framework” field is checked

Even with the Application ...

Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.