Professional Documents
Culture Documents
C#
Ng Quc Cng
Contents
Introduction
Classes, subjects, and methods
Graphical user interface
2
1.Introduction
3
1. Introduction
4
1.1. Microsofts .NET
6
1.2. Introduction to C# apps
7
1.2. Introduction to C# apps
8
1.2. Introduction to C# apps
9
1.2. Introduction to C# apps
11
1.3. Creating a simple app
12
2. Classes, methods
13
2. Classes, methods
Methods
The method describes the mechanisms that actually
perform its tasks.
The method hides from its user the complex tasks that it
performs.
14
2. Classes, methods
Classes
In C#, we begin by creating an app unit called a class to
house (among other things) a method.
In a class, you provide one or more methods that are
designed to perform the classs tasks.
Example
a class that represents a bank account might contain one
method to deposit money in an account, another to
withdraw money from an account and a third to inquire
what the current account balance is.
15
2. Classes, methods
Objects
Just as you cannot drive an engineering drawing of a car,
you cannot drive a class.
Just as someone has to build a car from its engineering
drawings before you can actually drive it, you must build
an object of a class before you can make an app perform
the tasks the class describes.
16
3. Graphical user interface
17
3. 1. Windows forms
18
3. 1. Windows forms
19
3. 2. Event Handling
20
3. 2. Event Handling
21
3. 2. Event Handling
22
3.3. Control properties and layout
23
3.4. Labels, Textboxes and Button
24
3.4. Labels, Textboxes and Button
25
3.4. Labels, Textboxes and Button
26
3.4. Labels, Textboxes and Button
27
3.4. Labels, Textboxes and Button
Example:
The user enters text into a password box and clicks the
Button, causing the text input to be displayed in the Label.
28
3.4. Labels, Textboxes and Button
29
3.5. Groupboxes and panels
30
3.5. Groupboxes and panels
31
3.5. Groupboxes and panels
32
3.5. Groupboxes and panels
Example:
uses a GroupBox and a Panel to arrange Buttons.
When these Buttons are clicked, their event handlers
change the text on a Label.
33
3.5. Groupboxes and panels
34
3.5. Groupboxes and panels
35
3.6. Checkboxes and Radio button
36
3.6. Checkboxes and Radio button
Checkboxes
A Check Box is a small square that either is blank or
contains a check mark.
You can also configure a CheckBox to toggle between
three states (checked, unchecked and indeterminate) by
setting its Three State property to true.
37
3.6. Checkboxes and Radio button
38
3.6. Checkboxes and Radio button
Example
allows the user to select CheckBoxes to change a Labels
font style.
39
3.6. Checkboxes and Radio button
40
3.6. Checkboxes and Radio button
41
3.6. Checkboxes and Radio button
Radio buttons
Radio buttons (defined with class RadioButton) are similar
to CheckBoxes in that they also have two states
selected and not selected.
However, Radio Buttons normally appear as a group, in
which only one RadioButton can be selected at a time.
42
3.6. Checkboxes and Radio button
Example
Using radio button
43