0% found this document useful (0 votes)
8 views43 pages

CHTP5e_09-Programming and Interfacing

Programming and Interfacing IN C PROGRAMME

Uploaded by

23145002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views43 pages

CHTP5e_09-Programming and Interfacing

Programming and Interfacing IN C PROGRAMME

Uploaded by

23145002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Programming and Interfacing

Structures

Ngô Quốc Cường


Contents

• Introduction
• Classes, objects, and methods
• Graphical user interface
1.Introduction

• In 2000, Microsoft announced the C# programming language.


C# has roots in the C, C++ and Java programming
languages.
• It has similar capabilities to Java and is appropriate for the
most demanding app-development tasks, especially for
building today’s large-scale enterprise apps, and web-based,
mobile and “cloud”-based apps.
• C# is object oriented.
1. Introduction

• C# has access to the powerful .NET Framework Class


Library—a vast collection of prebuilt classes that enable you
to develop apps quickly
1.1. Microsoft’s .NET

• In 2000, Microsoft announced its .NET initiative a broad


vision for using the Internet and the web in the development,
engineering, distribution and use of software.
• .NET permits you to create apps in any .NET-compatible
language (such as C#, Visual Basic, Visual C++ and many
others).
• The.NET Framework:
– executes apps and contains the .NET Framework Class
Library, which provides many capabilities that you’ll use to
build substantial C# apps quickly and easily.
– The Common Language Runtime (CLR), another key part
of the .NET Framework, executes .NET programs and
provides functionality to make them easier to develop and
debug.
1.2. Introduction to C# apps

• Example 1: Displaying a line of text


1.2. Introduction to C# apps

• Example 1: Displaying a line of text


• Line 3: using Directive

• is a using directive that tells the compiler where to look for a


class that’s used in this app.
• A great strength of Visual C# is its rich set of predefined
classes that you can reuse.
– These classes are organized under namespaces.
1.2. Introduction to C# apps

• Example 1: Displaying a line of text


• Line 5: Class declaration

• begins a class declaration for the class Welcome1.


• Every app consists of at least one class declaration that’s
defined by the programmer.
1.2. Introduction to C# apps

• Example 1: Displaying a line of text


• Line 8:

• The parentheses after the identifier Main indicate that it’s an


app building block called a method.
• Class declarations normally contain one or more methods.
1.2. Introduction to C# apps

• Example 1: Displaying a line of text


• Body of a Method Declaration
– The left brace in line 9 begins the body of the method
declaration. A corresponding right brace must end the
method’s body (line 11).
– Line 10 in the body of the method is indented between the
braces.
• Displaying a Line of Text

• Class Console provides standard input/output capabilities


that enable apps to read and display text in the console
window from which the app executes.
• The Console.WriteLine method displays a line of text in the
console window.
1.2. Introduction to C# apps

• Example 1: Displaying a line of text


• Statements
– The entire line 10, including Console.WriteLine, the
parentheses, the argument "Welcome to C#
Programming!“ in the parentheses and the semicolon(;), is
called a statement.
1.3. Creating a simple app

• Creating the console app


2. Classes, methods

• Suppose you want to drive a car and make it go faster by


pressing down on its accelerator pedal. What must happen
before you can do this? Well, before you can drive a car,
someone has to design it. A car typically begins as
engineering drawings, similar to the blueprints used to design
a house. These engineering drawings include the design for
an accelerator pedal to make the car go faster. The pedal
“hides” the complex mechanisms that actually make the car
go faster, just as the brake pedal “hides” the mechanisms
that slow the car and the steering wheel “hides” the
mechanisms that turn the car. This enables people with little
or no knowledge of how engines work to drive a car easily.
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.
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 class’s 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.
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.
3. Graphical user interface

• A graphical user interface (GUI) allows a user to interact


visually with a program.
• GUIs are built from GUI controls (which are sometimes called
components or widgets—short for window gadgets).
3. 1. Windows forms

• Windows Forms is one library that can be used to create


GUIs.
• A Form is a graphical element that appears on your
computer’s desktop.
3. 1. Windows forms
3. 2. Event Handling

• Normally, a user interacts with an app’s GUI to indicate the


tasks that the app should perform.
• When the user interacts with a GUI component, the
interaction—known as an event — drives the program to
perform a task.
• Common events:
– Clicking a button
– Typing in a textbox
– Selecting items from a menu
– Closing a window
– Moving the cursor
3. 2. Event Handling
3. 2. Event Handling

• Locating event information


3.3. Control properties and layout
3.4. Labels, Textboxes and Button

• Labels provide text information (as well as optional images)


and are defined with class Label.
• A Label displays text that the user cannot directly modify.
• A Label’s text can be changed programmatically by modifying
the Label’s Text property.
3.4. Labels, Textboxes and Button

• A textbox (class TextBox) is an area in which either text can


be displayed by a program or the user can type text via the
keyboard.
• A password TextBox is aTextBox that hides the information
entered by the user.
• set the property Use System Password Char to true, the
TextBox becomes a password TextBox.
3.4. Labels, Textboxes and Button
3.4. Labels, Textboxes and Button

• A button is a control that the user clicks to trigger a specific


action or to select an option in a program.
• All the button classes derive from class ButtonBase
(namespace System.Windows.Forms).
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.
3.4. Labels, Textboxes and Button
3.5. Groupboxes and panels

• GroupBoxes and Panels are typically used to group several


controls of similar functionality or several controls that are
related in a GUI.
• The primary difference between these two controls is that
GroupBoxes can display a caption (i.e., text) and do not
include scrollbars, whereas Panels can include scrollbars and
do not include a caption.
3.5. Groupboxes and panels
3.5. Groupboxes and panels

• Creating a Panel with scrollbars.


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.
3.5. Groupboxes and panels
3.5. Groupboxes and panels
3.6. Checkboxes and Radio button

• C# has two types of state buttons that can be in the on/off or


true/false states—CheckBoxes and RadioButtons.
• Classes CheckBox and RadioButton are derived from class
ButtonBase.
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.
3.6. Checkboxes and Radio button
3.6. Checkboxes and Radio button

• Example
– allows the user to select CheckBoxes to change a Label’s
font style.
3.6. Checkboxes and Radio button
3.6. Checkboxes and Radio button
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.
3.6. Checkboxes and Radio button

• Example
• Using radio button

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy