Chapter 2: Intro to Visual C# Flashcards
A visual C# application project starts with creating its GUI with:
1) Designer
2) Toolbox
3) Properties window
In the Designer, an empty form is automatically created
1) An application’s GUI is made of forms and controls
2) Each form and control in the application’s GUI must have aname as ID.
Each form and control in the application’s GUI must have aname as ID. The default blank form is named
“Form1” automatically
The default empty form has a dimension (size) of
Pixels wide by pixels high
A form in Designer is enclosed with
Thin dotted lines called the bounding box
The bounding box has small sizing handles; you can use them
To resize the form
The appearance and the other characteristics of a GUI object are determined by
The object’s properties
The Properties window lists all properties
When selecting an object, its properties are displayed in Properties windows
Each property has 2 columns
- Left: Property’s name
- Right: Property’s value
Changing a Property’s Value select an object, such as
The Form, by clicking it once
Click View and select Properties if the Properties window is
Not available
Find the property’s name in the list and change its value
1) The Text property determines the text to be displayed in the form’s title bar
2) Example: Change the value from “Form1” to “My First Program”
Adding Controls to a Form: In the Toolbox, select the Control, then you can either:
- Double click the Button control
- Click and drag the button control to the form
On the form, you can
- Resize the control using its bounding box and sizing handles
- Move the control’s position by dragging it
- Change its properties in the Properties window
Rules for Naming Controls
Control’s names are identifiers of the controls
The naming convention are:
1) The first character must be a letter (lower or uppercase, does not matter) or an undercore
2) All other characters can be alphanumerical characters or underscores
3) The name cannot contain spaces
Creating the GUI for Your First Visual Application Component:
A form and a Button control
Creating the GUI for Your First Visual Application Component purpose:
1) Create the application’s GUI
2) Write the code that causes “Hello World” to appear when the user clicks the button (details are available in)
C# code is primarily organized in three ways:
1) Namespace: a container that holds classes
2) Class: a container that holds methods
3) Method: a group of one or more programming statements that perform some operations
A file that contains program code is called
A source code file
Each time a new project is created the following two source code files are automatically created:
1) Program.cs file
2) Form1.cs file
Program.cs file
Contains the application’s start up code to be executed when the application runs
Form1.cs file
Contain code that is associated with the Form1 form
A sample of Form1.cs:
- The using directives indicate which namespaces of .NET Framework this program will use
- The user-defined namespace of the project not .NET Framework namespaces
- Class declaration
- A method
C# code is organized as
Methods, which are contained inside classes, which are contained inside namespaces
GUI applications are event-driven which means they interact with
Users
A event is a user’s action such as
Mouse clicking, key pressing, etc.
Double clicking a control, such as Button, will link the control to a default Event Handler
1) An event handler is a method that executes when a specific event takes place
2) A code segment similar to the following will be created automatically
A message box (aka dialog box)
Displays a message
The .NET Framework provides a method named
MessageBox.Show()
C# can use it to pop up
A window and display a message
Placing it in the “myButton_Click” event handler can display the string in the message box when
The button is clicked
Label Controls displays
Text on a form and can be used to display unchanging text or program output
Commonly used properties are:
1) Text
2) Name
3) Font
4) BorderStyle
5) AutoSize
6) TextAlign
1) Text
Gets or sets the text associated with label control
2) Name
Gets or sets the name of label control
3) Font
Allows you to set the font, font style, and font size
4) BorderStyle
Allow you to display a border around the control’s text
5) AutoSize
Controls the way they can be resized
6) TextAlign
Set the text alignments
Handling Text Alignments
1) The TextAlign property supports the following values
2) You can select them by clicking the down-arrow button of the TextAlign property
By adding the bold lines to a button’s event handler, a Label control can display
Output of the application
Equal sign (=) is known as
Assignment operator
IntelliSense provides automatic code completion as you write
Programming statements
It provides an array of options that make language references
Easily accessible
PictureBox controls
Displays a graphic image on a form
Commonly used properties are:
1) Image
2) SizeMode
3) Visible
1) Image
Specifics the image that it will display
2) SizeMode
Specifies how the control’s image is to be displayed
3) Visible
Determines whether the control is visible on the form at run time
Programmers need to carefully arrange the sequence of statements in order to
Generate the correct results
Incorrect arrangement of sequence can cause
Logic errors
Comment are brief note that are placed in
A program’s source code to explain how parts of the program work
A line comment appears on one line in
A program
A block comment can
Occupy multiple consecutive lines in a program
Programmer frequently use blank lines and identation in their codes
To make the code more human readable
Dealing with Syntax Errors
Code editor examines each statement as you type it and report any syntax error that are found
If syntax error is found, it is underlined with
A jagged line
If syntax error exists and you attempt to
Compile and execute, you will see the following.