Read Microsoft Visual C# 2005 Express Edition: Build a Program Now! Online

Authors: Patrice Pelland

Tags: #General, #Computers, #C♯ (Computer program language), #Programming Languages, #C#, #Microsoft .NET Framework, #Computer Books: Languages, #Computer Graphics, #Application software, #C# (Computer program language), #Programming, #Microsoft Visual C# .NET, #Microsoft Visual C♯ .NET, #Electronic books, #Game Programming & Design, #Computing: Professional & Programming, #C (Computer program language), #Computers - Languages, #Programming Languages - C#, #Programming & scripting languages: general

Microsoft Visual C# 2005 Express Edition: Build a Program Now! (12 page)

BOOK: Microsoft Visual C# 2005 Express Edition: Build a Program Now!
6.87Mb size Format: txt, pdf, ePub
ads

10/24/05 3:03:29 PM

10/24/05 3:03:29 PM

Congratulations! You’ve just created your first two applications: a console application and a Windows application.

In Summary...

In this chapter, you learned some key information that will help you build on the skills you’ve started developing in the previous chapters. You learned the differences between a

Keywords and Links

console application and a Windows application. You started the product, went through the

to More Information

IDE, and learned its major components. You created two versions of the same application: a
Keywords
: declaring variables;

console application and a Windows application. While learning about console applications,
string concatenation

you also learned what the Solution Explorer is as well as how to search and use the product
Another good source

documentation and the Help system.

of information is the videos

from MSDN. These videos

In the next chapter, you’ll build on this knowledge and write a simple Web browser. For
were specifically created to

now, if you want to read more about some topics covered in this chapter, simply create a
cover the Visual C# 2005

search query by pressing F1 and then type in the keywords provided in the box to the left.
Express Edition product. You

I’ve also added a link to videos that are a good source of information to continue your
can find video for Lesson 1

learning.

at the following location:

http://go.microsoft.com/fwlink/

?linkid=44030&clcid=0x409

44

Microsoft Visual C# 2005 Express Edition: Build a Program Now!

CSX_chapter3.indd 44

CSX_chapter3.indd 44

10/24/05 3:03:30 PM

10/24/05 3:03:30 PM

Chapter 4

Create Your Own

Web Browser in Less

Than Five Minutes!

What Is a Project? , 46

Now that you’ve gotten a little experience with creating simple applications in Microsoft® Visual C#® 2005 Express Edition, you’ll build a more compli
What Is the Design

cated application in this chapter and finish it in Chapter 6. In this chapter,

Layout? , 47

you’ll start with the basic framework of the application; in the next two

Putting It All Together, 54

chapters, you’ll continue to learn new features and add them to enhance your project.

In this chapter, you’re going to learn how to build your own basic Web Ch4.indd 45

Ch4.indd 45

4
browser, and you’ll be able to do it in five minutes or less!

45

10/24/05 3:07:51 PM

10/24/05 3:07:51 PM

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. The project is a container for all 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 (i.e., binaries) on your hard drive, the version information, and many more settings that affect all of the characteristics of your application. For instance, it’s also storing programmer-defined application settings that are very important for the user experience. Users love to customize their software environment to their comfort level and personal style. A typical utilization of those user settings is to make sure the application can preserve user customization from one execution to another. A good example of custom user settings can be seen with your own user preferences in Internet Explorer, such as your home page address, your home page settings, which toolbars are displayed, and whether your toolbars are locked in size and so forth.

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 creating your application is going to become your project name. It will also become the default folder name on your hard drive where your application will be stored when you save your application. It will also become the default namespace of your application. A namespace is used to organize the classes in a single hierarchical structure. It does the same for any other types you might define. The creation of a namespace 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. They would create a namespace called AdventureWorks and put their ANewForm class in it to uniquely name their 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(es). AdventureWorks’s unique class would be AdventureWorks.ANewForm.

46

Microsoft C# 2005 Express Edition: Build a Program Now!

Ch4.indd 46

Ch4.indd 46

10/24/05 3:07:57 PM

10/24/05 3:07:57 PM

Now let’s suppose that 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 that you then define a new class and name it ANewForm. You might not be aware that a company called AdventureWorks also called their new class using the same name. Even though AdventureWorks might be doing completely different things with their class, a problem could arise because the two classes are named the same. Now suppose that 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).

What Is the Design Layout?

You will soon create a new design layout in the form designer. In doing this, you’ll be creating what the application contains and how its content is presented when the user executes the application.

To accomplish this phase of a project, you typically do not need to type a great deal of code; as explained later in this chapter, Visual Studio takes care of that for you. You simply have to worry about how your application looks. When you're done designing all the visual aspects to your liking, your next task usually involves attaching the source code to your visual layout so that your application reacts to and acts upon the user’s input. In this chapter, you will complete the basic layout. You will learn more advanced layout techniques in following chapters. Let’s start the next project: a simple Web browser.
Chapter 4: Create Your Own Web Browser in Less Than Five Minutes!

47

Ch4.indd 47

Ch4.indd 47

10/24/05 3:07:57 PM

10/24/05 3:07:57 PM

TO CREATE A SIMPLE WEB BROWSER

Start Visual C# 2005 Express Edition by clicking
Start, All Programs,
and
Microsoft Visual C# 2005

1
Express Edition
.

Create a new Microsoft Windows® Application Project using any of the techniques shown in the pre2 vious chapters through either the
File
menu or the New Project icon in the toolbar. Name the new application
MyOwnBrowser
.

On the design surface, you’ll see the empty Windows Form with a title bar named
Form1
. Click on 3 the title bar once. By default, you don't see the Properties window. To view it, select the
View
menu and then select
Properties Window
. Look over to the Properties window on the bottom right of the IDE, as shown in Figure 4-1.

Figure 4-1

Properties window for MyOwnBrowser

application Form control

48

Microsoft C# 2005 Express Edition: Build a Program Now!

Ch4.indd 48

Ch4.indd 48

10/24/05 3:07:57 PM

10/24/05 3:07:57 PM

We’ll be using most of the properties you see listed here! Right now what is important for you to understand is that most of these properties influence how the control you have selected behaves or what it looks like when you execute your application.

For all samples in this book, I suggest that you sort the properties list in ascending alphabetical order; it will be much easier to find properties that I reference in the examples. To sort the properties in alphabetical order, click on the
Alphabetical
button from the Properties window toolbar. The other option is to arrange the controls by categories, but this might slow down your progress throughout this book. Whenever you select a property, you’ll see a brief description of its usage at the bottom of the Properties window. Refer to Figure 4-1 as an example. In this case, the text property was selected. At the bottom of the Properties window, you can see a succinct text message describing the function of the text property. As mentioned in Chapter 3, my best advice for learning this software is to try, try, and try again. There are a variety of tools in Visual C# 2005 Express Edition and are therefore many possibilities. You will learn to use most of these tools by using this book, but it’s impossible to learn all variations and possibilities if you don’t do some exploring on your own. With that in mind, to understand the effect of a change on a particular property, try all different possible values. Each time you modify a property, build and check the execution. However, don’t make more than one change at a time. It will be difficult for you to know which one of your changes actually triggered a visual modification. By exploring more than one possibility, you’ll be able to see the effect of your changes immediately.

I M P O R T A N T

Make sure you have selected the Form control named
Form1
in step 3 and then modify the following
Some properties have a (+) beside

4

them, which means that it’s a tree

properties using the values in Table 4-1. The property name to modify is located in the left column,
view property. Whenever you click

and the value to which to set the property is located in the right column. You may have already completed
the (+), you’ll expand this prop-

this step, but to facilitate your data entry, verify that you have sorted the properties in ascending alphabeti
erty to display the property attri-
cal order.

butes, which you will then be able

to set. Whenever you will be asked

to enter values for properties that

are in a tree view, I will use the

Property Value

following notation structure as

found in this format:
Size:Width
,

Text
My

Own

Browser

which refers to the Size property

and the Width attribute.

Size:Width
640

Size:Height
480

Table 4-1

List of Form properties to change

Chapter 4: Create Your Own Web Browser in Less Than Five Minutes!

49

Ch4.indd 49

Ch4.indd 49

10/24/05 3:07:58 PM

10/24/05 3:07:58 PM

BOOK: Microsoft Visual C# 2005 Express Edition: Build a Program Now!
6.87Mb size Format: txt, pdf, ePub
ads

Other books

Vanity Fair by William Makepeace Thackeray
I See You (Oracle 2) by Meghan Ciana Doidge
Devotion by Megan Derr