SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Introduction to Windows
Programming
Chapter Objectives
Differentiate between the functions of Windows
applications and console applications
Learn about graphical user interfaces
Become aware of some elements of good design
Use C# and Visual Studio to create Windows-based
applications
Chapter Objectives (continued)
Create Windows forms and be able to change form
properties
Add control objects such as buttons, labels, and text
boxes to a form
Work through a programming example that illustrates
the chapter’s concepts
Windows Application Basics
 Windows Forms is the event base smart-client component of the
.NET Framework.
 Application run locally on users' computers.Once launched
 Set of managed libraries that enable common application tasks such
as reading and writing to the file system.
 A form is a visual surface on which you display information to the
user. You commonly build Windows Forms applications by placing
controls on forms and developing responses to user actions, such as
mouse clicks or key presses. A control is a discrete user interface
(UI) element that displays data or accepts data input.
Graphical User Interfaces
Interface: front end of a program
 Visual image you see when you run a program
Graphical user interface (GUI) includes:
 Menus
 Text in many different colors and sizes
 Other controls (pictures, buttons, etc.)
Windows Applications
Reference and import System.Windows.Forms
namespace
Class heading definition
 Includes not only the class name, but a colon
followed by another class name
 Derived class (first class)
 Base class (second class)
 public class Form1 : Form
Derived classes inherit from base class
Windows Applications (continued)
Text
 A property for setting/getting title bar caption
Name
 Unique name for all controls
Windows forms/controls offer many properties
including Text, Color, Font, and Location,Size
Execution begins in Main( ) method
 Main( ) is located in Program.cs file for the application
 Call to Run( ) method places application in process loop
using System.Windows.Forms; // Line 1
namespace Windows0
{
public class Form1 : Form // Line 2
{
public Form1( ) // Line 3
{
InitializeComponent();
Text = "Simple Windows Application"; // Line 4
}
}
}
New
namespace
referenced
Constructor
Base class
Sets
title bar
caption
Starts
process
loop
Windows Application (continued)
Figure 8-1 Windows-based form
Output
generated
from sample
from
application
Elements of Good Design
Appearance matters
 Human-computer interaction (HCI) research
Design considerations
 Consistency
 Alignment
 Avoid Clutter
 Color
 Target Audience
Use Visual Studio to Create Windows-
based Applications
Windows
Application
template
Browse
to
location
to store
your
work
Select
File
New
Project
Name
Figure 8-2 Visual Studio New Windows application
Windows-based Applications
Properties
Window
Design View
Toolbox
Switch
between
Design and
Code view
using View
menu
Figure 8-3 Initial design screen
Windows-based Applications (continued)
Figure 8-4 Dockable windows
Properties
Auto-hide
Solution
Explorer
pushpin
Windows Forms
Extensive collection of Control classes
Top-level window for an application is called a Form
Each control has large collection of properties
and methods , Events
 Select property from an alphabetized list (Properties
window)
 Change property by clicking in the box and selecting
or typing the new entry
Windows Form Properties
Properties
Property value
Figure 8-5 Properties window
Categorized
Alphabetical
Events
Windows Form Properties (continued)
Windows Form Events
Add code to respond to events, like button clicks
From the Properties window, select the lightening bolt
(Events)
 Double-click on the event name to generate code
 Registers the event as being of interest
 Adds a heading for event-handler method
Windows Form Properties (continued)
Events
button
selected
Figure 8-6 Form1 events
Windows Form – Closing Event
Code automatically added to register event
this.Closing += new System.ComponentModel.CancelEventHandler
(this.Form1_Closing);
Code automatically added for method heading
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
}
You can add statement to event-handler method
body
MessageBox.Show("Hope you are having fun!");
Simple Windows Application
New with Visual Studio 2010, the IDE separates the
source code into three separate files
 Form1.cs: Normally this is the only one you edit
 Form1.Designer.cs: Holds the auto-generated code
 Program.cs: Contains the Main( ) method, where
execution always begins
Form1.cs and Form1.Designer.cs both include
partial class definitions for the Form1 class
Windows Form Events (continued)
Figure 8-7 Solution Explorer window
Expand Form1.cs
node to reveal the
Form1.Designer.cs
file
Controls
Controls are all classes
 Button, Label, TextBox, ComboBox, MainMenu,
ListBox, CheckBox, RadioButton, and
DateTimePicker …
Each comes with its own predefined properties and
methods
Each fires events
Each is derived from the
System.Windows.Forms.Control class
Controls (continued)
Dots
indicate
other
classes
are
derived
from the
class
Figure 8-9 Control class hierarchy
Standard Controls
Figure 8-10 Windows Forms controls
Creating a form
Properties set for the Form
container
Sample Form with Controls
Figure 8-11 GUI controls
Controls (continued)
Two procedures to place controls
 From Toolbox, double-click on control or drag and drop
Move, resize, and delete controls
Format controls
 Align controls
 Make same size
 Horizontal and vertical spacing
Properties of the Control Class
Methods of the Control Class
Label Objects
Provides descriptive text or labels for other controls
Instantiate object
Label labelName = new Label( );
Add control to Form
this.Controls.Add(labelName);
Set property values (some from Control class)
 Text; TextAlign; Font; Location
Adding Labels to Form
Add Label objects, then set their
properties using the Properties
window
(View Properties window)
TextBox Objects
Used to enter data or display text during run time
 Used for both input and output
Instantiate object
TextBox textBoxName = new TextBox( );
Add control to Form
this.Controls.Add(TextBoxName);
Interesting properties
 MultiLine, ScollBars, MaxLength, PasswordChar,
CharacterCasing
TextBox Objects (continued)
Adding TextBox Objects to Form…
Add TextBox objects,
then set their property
values
Button
Enables user to click button to perform task
 If button has event-handler method and is registered as
an event to which your program is planning to respond,
event-handler method is called automatically when
button clicked
Button object’s properties, methods, and events
 Inherits from Control
 Text, Enabled, Focused, TabIndex
Adding Button Objects to Form
Add Button objects,
then set their property
values
Adding Button Objects to Form (continued)
Figure 8-14 Events
Click to see
list of events
Double-click
to create an
event-handler
method
Add other controls to form
Combo box
Menu strip (Call Sample Salary Form)
List box
Date Time picker
Check box
Radio button
Check box list
Error provider
Sample Salary Calculator
Timer Control
A Timer control raises an event at a given interval.
 If you need to execute some code after certain interval of
time continuously, you can use a timer control.
Windows Forms have a Timer control that can be used at
design time as well as at run-time
Properties
Enabled
 Gets or sets whether the timer is running.
Interval
 Gets or sets the time, in milliseconds, before the Tick event is raised
relative to the last occurrence of the Tick event.
Methods and Event
Method
 Protected method OnTick Raises the Tick event.
 Public method Start Starts the timer.
 Public method Stop Stops the timer.
Event
 Tick
 Occurs when the specified timer interval has elapsed and the timer is
enabled.
Question ??

Weitere ähnliche Inhalte

Was ist angesagt?

Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and filesMarcello Thiry
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Architecture of .net framework
Architecture of .net frameworkArchitecture of .net framework
Architecture of .net frameworkThen Murugeshwari
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mountingrajshreemuthiah
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Abou Bakr Ashraf
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Elizabeth alexander
 

Was ist angesagt? (20)

Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Architecture of .net framework
Architecture of .net frameworkArchitecture of .net framework
Architecture of .net framework
 
Functions in C
Functions in CFunctions in C
Functions in C
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mounting
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
Web controls
Web controlsWeb controls
Web controls
 

Andere mochten auch

Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Bhushan Mulmule
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application veera
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Salim M
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computersimran153
 

Andere mochten auch (6)

Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 

Ähnlich wie 4.C#

06 win forms
06 win forms06 win forms
06 win formsmrjw
 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxEliasPetros
 
Visual basic concepts
Visual basic conceptsVisual basic concepts
Visual basic conceptsmelody77776
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxAOmaAli
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptBhuvanaR13
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxscroghamtressie
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introductionbloodyedge03
 

Ähnlich wie 4.C# (20)

06 win forms
06 win forms06 win forms
06 win forms
 
Ch01
Ch01Ch01
Ch01
 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
 
unit 4.docx
unit 4.docxunit 4.docx
unit 4.docx
 
Visual basic concepts
Visual basic conceptsVisual basic concepts
Visual basic concepts
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptx
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.ppt
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
 

Mehr von Raghu nath

Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Selection sort
Selection sortSelection sort
Selection sortRaghu nath
 
Binary search
Binary search Binary search
Binary search Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithmsRaghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp roleRaghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 

Mehr von Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

4.C#

  • 2. Chapter Objectives Differentiate between the functions of Windows applications and console applications Learn about graphical user interfaces Become aware of some elements of good design Use C# and Visual Studio to create Windows-based applications
  • 3. Chapter Objectives (continued) Create Windows forms and be able to change form properties Add control objects such as buttons, labels, and text boxes to a form Work through a programming example that illustrates the chapter’s concepts
  • 4. Windows Application Basics  Windows Forms is the event base smart-client component of the .NET Framework.  Application run locally on users' computers.Once launched  Set of managed libraries that enable common application tasks such as reading and writing to the file system.  A form is a visual surface on which you display information to the user. You commonly build Windows Forms applications by placing controls on forms and developing responses to user actions, such as mouse clicks or key presses. A control is a discrete user interface (UI) element that displays data or accepts data input.
  • 5. Graphical User Interfaces Interface: front end of a program  Visual image you see when you run a program Graphical user interface (GUI) includes:  Menus  Text in many different colors and sizes  Other controls (pictures, buttons, etc.)
  • 6. Windows Applications Reference and import System.Windows.Forms namespace Class heading definition  Includes not only the class name, but a colon followed by another class name  Derived class (first class)  Base class (second class)  public class Form1 : Form Derived classes inherit from base class
  • 7. Windows Applications (continued) Text  A property for setting/getting title bar caption Name  Unique name for all controls Windows forms/controls offer many properties including Text, Color, Font, and Location,Size Execution begins in Main( ) method  Main( ) is located in Program.cs file for the application  Call to Run( ) method places application in process loop
  • 8. using System.Windows.Forms; // Line 1 namespace Windows0 { public class Form1 : Form // Line 2 { public Form1( ) // Line 3 { InitializeComponent(); Text = "Simple Windows Application"; // Line 4 } } } New namespace referenced Constructor Base class Sets title bar caption Starts process loop
  • 9. Windows Application (continued) Figure 8-1 Windows-based form Output generated from sample from application
  • 10. Elements of Good Design Appearance matters  Human-computer interaction (HCI) research Design considerations  Consistency  Alignment  Avoid Clutter  Color  Target Audience
  • 11. Use Visual Studio to Create Windows- based Applications Windows Application template Browse to location to store your work Select File New Project Name Figure 8-2 Visual Studio New Windows application
  • 12. Windows-based Applications Properties Window Design View Toolbox Switch between Design and Code view using View menu Figure 8-3 Initial design screen
  • 13. Windows-based Applications (continued) Figure 8-4 Dockable windows Properties Auto-hide Solution Explorer pushpin
  • 14. Windows Forms Extensive collection of Control classes Top-level window for an application is called a Form Each control has large collection of properties and methods , Events  Select property from an alphabetized list (Properties window)  Change property by clicking in the box and selecting or typing the new entry
  • 15. Windows Form Properties Properties Property value Figure 8-5 Properties window Categorized Alphabetical Events
  • 16. Windows Form Properties (continued)
  • 17. Windows Form Events Add code to respond to events, like button clicks From the Properties window, select the lightening bolt (Events)  Double-click on the event name to generate code  Registers the event as being of interest  Adds a heading for event-handler method
  • 18. Windows Form Properties (continued) Events button selected Figure 8-6 Form1 events
  • 19. Windows Form – Closing Event Code automatically added to register event this.Closing += new System.ComponentModel.CancelEventHandler (this.Form1_Closing); Code automatically added for method heading private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { } You can add statement to event-handler method body MessageBox.Show("Hope you are having fun!");
  • 20. Simple Windows Application New with Visual Studio 2010, the IDE separates the source code into three separate files  Form1.cs: Normally this is the only one you edit  Form1.Designer.cs: Holds the auto-generated code  Program.cs: Contains the Main( ) method, where execution always begins Form1.cs and Form1.Designer.cs both include partial class definitions for the Form1 class
  • 21. Windows Form Events (continued) Figure 8-7 Solution Explorer window Expand Form1.cs node to reveal the Form1.Designer.cs file
  • 22. Controls Controls are all classes  Button, Label, TextBox, ComboBox, MainMenu, ListBox, CheckBox, RadioButton, and DateTimePicker … Each comes with its own predefined properties and methods Each fires events Each is derived from the System.Windows.Forms.Control class
  • 24. Standard Controls Figure 8-10 Windows Forms controls
  • 25. Creating a form Properties set for the Form container
  • 26. Sample Form with Controls Figure 8-11 GUI controls
  • 27. Controls (continued) Two procedures to place controls  From Toolbox, double-click on control or drag and drop Move, resize, and delete controls Format controls  Align controls  Make same size  Horizontal and vertical spacing
  • 28. Properties of the Control Class
  • 29. Methods of the Control Class
  • 30. Label Objects Provides descriptive text or labels for other controls Instantiate object Label labelName = new Label( ); Add control to Form this.Controls.Add(labelName); Set property values (some from Control class)  Text; TextAlign; Font; Location
  • 31. Adding Labels to Form Add Label objects, then set their properties using the Properties window (View Properties window)
  • 32. TextBox Objects Used to enter data or display text during run time  Used for both input and output Instantiate object TextBox textBoxName = new TextBox( ); Add control to Form this.Controls.Add(TextBoxName); Interesting properties  MultiLine, ScollBars, MaxLength, PasswordChar, CharacterCasing
  • 34. Adding TextBox Objects to Form… Add TextBox objects, then set their property values
  • 35. Button Enables user to click button to perform task  If button has event-handler method and is registered as an event to which your program is planning to respond, event-handler method is called automatically when button clicked Button object’s properties, methods, and events  Inherits from Control  Text, Enabled, Focused, TabIndex
  • 36. Adding Button Objects to Form Add Button objects, then set their property values
  • 37. Adding Button Objects to Form (continued) Figure 8-14 Events Click to see list of events Double-click to create an event-handler method
  • 38. Add other controls to form Combo box Menu strip (Call Sample Salary Form) List box Date Time picker Check box Radio button Check box list Error provider
  • 40. Timer Control A Timer control raises an event at a given interval.  If you need to execute some code after certain interval of time continuously, you can use a timer control. Windows Forms have a Timer control that can be used at design time as well as at run-time
  • 41. Properties Enabled  Gets or sets whether the timer is running. Interval  Gets or sets the time, in milliseconds, before the Tick event is raised relative to the last occurrence of the Tick event.
  • 42. Methods and Event Method  Protected method OnTick Raises the Tick event.  Public method Start Starts the timer.  Public method Stop Stops the timer. Event  Tick  Occurs when the specified timer interval has elapsed and the timer is enabled.