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! (18 page)

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

11 The third way to rename a symbol, and in this case only for project elements, is to do it directly in Solution Explorer. Even though earlier we changed the Form1 variable into something more meaningful, the file name Form1 hasn’t changed because it’s not in the source code; it's in the Solution Explorer and contained in the project, so it’s still Form1.cs. For consistency, right-click the filename Form1.cs in the Solution Explorer, then select
Rename
and change the filename to
TestProjectFormOtherName.cs
. Two things will happen: first, you’ll see that the filename and all dependent filenames are automatically changed to the new name; and second, you’ll see that all references to TestProjectForm are now changed to TestProj ectFormOtherName. You can verify this renaming change by pressing Ctrl+F and performing a search on the old name (form1.cs).

Refactoring–Extract Method

It’s common when you develop an application that a block of code turns into a mega method that does a lot more than the original functionality it was supposed to provide. Therefore you need to re-organize your code and maybe break the problem into smaller pieces. That’s where the refactoring–extract method will become your friend. With this refactoring functionality you just have to select a block of code within a method, right-click, select Refactor, and then select Extract Method… Visual C# 2005 Express will then create a private method with the selected block of code and call that method where the code was. If the block of code uses local variables from the original method they will be automatically passed as argument to the new method. Look at Figure 5-17a and b to see what it looks like before the refactoring, during and after the refactoring.

70

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

C05.indd 70

C05.indd 70

10/24/05 3:15:47 PM

10/24/05 3:15:47 PM

Figure 5-17

Refactoring–Extract Method in action

before and after

Common Windows Controls

I will not spend a lot of time here explaining all the details and properties of each control in the toolbox. This book is not a reference about Windows Forms programming. Other books do a great job with that topic. However, Table 5-1 provides a quick introduction to the most common controls you will find in most Windows Applications.

There are many more controls than those shown here. But this table should make it clear that there are a plethora of controls available to perform many tasks. To save time and effort, you can usually find a control to provide the results you want with very little effort. It is especially desirable if the control you pick can restrict choices or how the data is selected without having to perform any other validation. In software development, always keep the 80/20 rule in mind: 80 percent of results for 20 percent effort.

Chapter 5: Creating Your First Full Windows Application

71

C05.indd 71

C05.indd 71

10/24/05 3:15:48 PM

10/24/05 3:15:48 PM

Table 5-1

Common Windows applications

Visual representation

Name

Description

controls

Button

Indicates that the user makes a decision

and wants to communicate his action.

In your application, a button clicked by

the user triggers an event that your code

needs to handle.

TextBox

The text box is used to get user input.

On the screen it can be a single or multiline control. It can also provide password character masking if you need this

behavior in your application. It’s a good

choice to input information that is not

restrictive in choices, for instance a

Boolean decision like yes/no, on/off, or a

list of specific choices like a list of country

names. It’s good for names, addresses,

phone numbers, URLs, etc.

Label

The label is usually simple text used to

describe other controls. It is not an interactive control.

RadioButton

Multiple choices are offered but the user

can only pick one from the list. Let’s say

you have an application and you want to

provide the option to print in grayscale

or color. You could use two radio buttons

to select the desired method.

Continued on next page

72

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

C05.indd 72

C05.indd 72

10/24/05 3:15:48 PM

10/24/05 3:15:48 PM

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

Other books

The Lovegrove Hermit by Rosemary Craddock
The Balkan Trilogy by Olivia Manning
James Acton 01 - The Protocol by J. Robert Kennedy
Human to Human by Rebecca Ore
Villains by Necessity by Eve Forward
The Local News by Miriam Gershow
Nobody's Fool by Richard Russo
Darling Jenny by Janet Dailey
Square Wave by Mark de Silva