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
to naming the variable that rep-
resents controls on the design
■ What happens if I enter an invalid URL?
surface. In this book, I’m going to
use up to three letters to describe
■ What happens if I enter anything I feel like?
and identify the control type by
looking at its name, such as “btn”
for a button control. The vari-
My answer to you is simply, “Try it. Try it now.” The real deal is that your Web browser
able name then becomes btnGo.
will actually behave like any other Web browser and will navigate to whatever URL is typed
I will introduce the list when I
talk about common controls in
into the text box. If you don’t type anything, clicking on the GO button will have no effect.
Chapter 5.
If you type anything you feel like, the browser control will come back with a Page not found or Code 404 page.
Now is your time to experiment. Remember this book’s rule: TRY, TRY, TRY. So go ahead and play with it. Change some of the properties and see the results at run time. Although we haven’t used many features yet, you’ll add more in Chapter 6. This project is far from over! By adding new features, you’ll arrive at a point where your application will start to look much more familiar.
54
Microsoft C# 2005 Express Edition: Build a Program Now!
Ch4.indd 54
Ch4.indd 54
10/24/05 3:08:01 PM
10/24/05 3:08:01 PM
In Summary...
In this chapter, you learned how to build a Web browser. You started to:
■ Add more than one control to the designer surface
Links to More
■
Information
Set properties in the Properties window
Other good sources of infor-
■ Wire an event to a control and learn how to add code that will execute when the event
mation are the videos from
is triggered
MSDN specifically created
to cover the Visual C# 2005
In this example, you've linked many OOP concepts by using only one line of code.
Express Edition product. The
You've added the code to respond to the button click event by calling the Navigate
videos for Lessons 2 and 7
method of your Web browser object. Your Web browser navigated to a URL passed in as an
cover some of the topics you
argument to the Navigate method. The argument for the Navigate method was passed in
have just learned and will pro-
vide you with another point of
using the text box control Text property. Everything was completed and fully working just by
view. You can find the videos
tweaking some properties and adding ONLY one line of code! That’s what I call productivity.
for Lessons 2 and 7 by typ-
In the next chapter, you’ll continue this process by learning all of the major features of
ing in the following hyperlink:
Visual C# 2005 Express Edition. You’ll become more productive at developing applications
http://go.microsoft.com/fwlink/
by learning features such as IntelliSense®, snap lines, code snippets, smart tags, refactoring,
?linkid=44030&clcid=0x409.
and much more.
Chapter 4: Create Your Own Web Browser in Less Than Five Minutes!
55
Ch4.indd 55
Ch4.indd 55
10/24/05 3:08:02 PM
10/24/05 3:08:02 PM
Ch4.indd 56
Ch4.indd 56
10/24/05 3:08:02 PM
10/24/05 3:08:02 PM
Creating Your
First Full Windows
Application
Snap and Align Those
In Chapter 4, you started building your own Web browser, and in Chapter 5
Controls Using Snap
you'll add to its capabilities. But before you do that, I want to introduce
Lines, 58
some Microsoft® Visual C#® 2005 features that will help you develop your Microsoft Windows® programming knowledge and skills. We’ll look into
Using IntelliSense
—
Your
some of the more useful rapid application development (RAD) features of
New Best Friend!, 59
Visual C# 2005 Express Edition.
Renaming and
C05.indd 57
C05.indd 57
5
NOTE
Refactoring, 66
You can find all RAD features described in this chapter in every version of
Visual Studio 2005. So if you already know how to use these features in the
Common Windows
Express Edition and decide to explore any of the other versions of Visual
Controls, 71
Studio 2005, you'll find it much easier to switch and be productive.
What Happens When an
If you already have some programming experience, you’ll be pleasantly
Event Is Triggered?, 74
surprised to find that it’s even easier to program using Visual C# 2005
Express Edition.
57
10/24/05 3:15:34 PM
10/24/05 3:15:34 PM
Snap and Align Those Controls Using Snap Lines
Not being a very skilled user interface designer myself, I’ve always had problems working on a program with many controls to align. Even more difficult was trying to get the alignment right the first time I dropped the controls onto the form. I’ve always had to go to the Properties window and align the controls manually by entering their
x
and
y
coordinates, which slows down the development process quite a bit! Again, let me reiterate one of the philosophies the Visual C# 2005 team had in mind when creating this awesome new product. They wanted to make sure you didn’t have to perform multiple steps at several different places to accomplish a simple task. And they succeeded with a lot of new features; one of these is the new snap lines feature that allows you to easily align objects on the designer surface. Let’s do an exercise so you can see the snap lines feature in action. T I P
T-
When you have many controls to
drop on the designer surface, you
can save some time by “pinning”
TO CREATE A NEW WINDOWS FORM USING SNAP LINES
down the toolbox so that it stays
open. To disable the AutoHide
feature, click the Pin button on
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
top of the toolbox. To re-enable
shown in the previous chapters by using either the File menu or the New Project icon in the toolbar. Name
the AutoHide feature, click the Pin
the new application
TestProject
.
button again.
You should see the designer surface. If you don't, right-click
2 on the filename
Form1.cs
in the Solution Explorer and
choose
View Designer
. Then, using the toolbox, drag three labels and three text box controls onto the design surface.
Stack the labels vertically. A thin blue line (a snap line) will
3 appear on either the right side or the left side of the labels to
help guide the alignment. When the labels are aligned correctly,
release the label control.
As shown in Figure 5-1, a small blue horizontal line also appears to
Figure 5-1
the left of the label control. This line represents the minimum space
Snap lines in action with two label controls
between a control and another control or between a control and
its container.
58
Microsoft Visual C# 2005 Express Edition: Build a Program Now!
C05.indd 58
C05.indd 58
10/24/05 3:15:40 PM
10/24/05 3:15:40 PM