Creating Your Own Web Browser in Less Than Five Minutes with Microsoft Visual C# 2008 Express Edition

  • 3/5/2008
In this chapter from Microsoft Visual C# 2008 Express Edition: Build a Program Now!, you’ll learn how to build your own basic Web browser, and you’ll be able to do it in five minutes or less!

Now that you’ve gotten a little experience creating simple applications in Microsoft Visual C# 2008 Express Edition, you’ll build a more complicated application in this chapter and finish it in Chapter 6, "Modifying Your Web Browser". In this chapter, you’ll start with the basic framework of the application; in the next two chapters, you’ll continue to learn new features and then use them to enhance your project.

Specifically, in this chapter you’ll learn how to build your own basic Web browser, and you’ll be able to do it in five minutes or less!

What Is a Project?

In the previous chapter, you created a project to hold your source code. I’ll now take a moment to explain what a project is and what information it contains. A project is a container for all the items in your application, such as forms, source code, and resources. It also stores important configuration data that belongs to the application as a whole: the location of the executable (that is, binaries) on your hard disk, the version information, and many more settings that affect the characteristics of your application. For instance, a project stores programmer-defined application settings that are important for the user experience. Users love to customize their software environment to reflect their comfort level and personal styles, for example. You’ve probably set up specific user preferences in Windows Internet Explorer, such as your home page address, your home page settings, which toolbars are displayed, whether your toolbars are locked in size, and so forth. A typical use of application settings in a project is to make sure the application can preserve user customizations from one execution to another.

In the next chapter, you’ll learn about some of the most important settings stored in the project configuration file and how to use them in your application. In the final chapter of this book, you will use programmatic techniques to preserve the user’s settings and customizations.

The name you choose when you create your application becomes your project’s name. It also becomes the default folder name on your hard disk where your application is stored when you save it, and this name becomes the default namespace of your application. A namespace is used to organize the classes in a program in a single, logical hierarchical structure. It does the same for any other types you might define. The creation of a namespace also helps prevent naming collisions. What is a naming collision? Let’s look at an example to illustrate this concept.

Suppose a company called AdventureWorks wrote a new Windows Forms class named ANewForm. The company would create a namespace called AdventureWorks and put its ANewForm class in it to uniquely name the class. The fully qualified name of a class is always composed of the namespace followed by a dot and then the name of the class or classes. Therefore, AdventureWorks’s unique class would be AdventureWorks.ANewForm.

Now let’s suppose you are creating a new project using Visual Studio and decide to name your project MyLibrary. Visual Studio would then create for you a namespace called MyLibrary. Suppose you then define a new class and name it ANewForm. You might not be aware that a company called AdventureWorks also called its new class using the same name. Even though AdventureWorks might be performing completely different tasks with its class, a problem could arise because the two classes are named the same.

Now suppose you’re trying to use both classes called ANewForm in your new application. If you simply use ANewForm, the compiler will not be able to determine which ANewForm class you want to use—the one from your library or the one from the AdventureWorks library; this is a naming collision. By prefixing the class name with the namespace name, you are then telling the compiler exactly which class you want to use (AdventureWorks.ANewForm or MyLibrary.ANewForm).