SlideShare a Scribd company logo
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 ??

More Related Content

What's hot

introduction to visual basic PPT.pptx
introduction to visual basic PPT.pptxintroduction to visual basic PPT.pptx
introduction to visual basic PPT.pptx
classall
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
Jeanie Arnoco
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Assemblies
AssembliesAssemblies
Assemblies
Janas Khan
 
Asp.net basic
Asp.net basicAsp.net basic
Asp.net basic
Neelesh Shukla
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
DrSonali Vyas
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari
 
Event handling
Event handlingEvent handling
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
rishisingh190
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
C# Framework class library
C# Framework class libraryC# Framework class library
C# Framework class library
Prem Kumar Badri
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
Sireesh K
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
priya Nithya
 
Web controls
Web controlsWeb controls
Web controls
Sarthak Varshney
 
Notification android
Notification androidNotification android
Notification android
ksheerod shri toshniwal
 

What's hot (20)

introduction to visual basic PPT.pptx
introduction to visual basic PPT.pptxintroduction to visual basic PPT.pptx
introduction to visual basic PPT.pptx
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Assemblies
AssembliesAssemblies
Assemblies
 
Asp.net basic
Asp.net basicAsp.net basic
Asp.net basic
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Event handling
Event handlingEvent handling
Event handling
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
 
Java swing
Java swingJava swing
Java swing
 
C# Framework class library
C# Framework class libraryC# Framework class library
C# Framework class library
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Database Connection
Database ConnectionDatabase Connection
Database Connection
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
 
Web controls
Web controlsWeb controls
Web controls
 
Notification android
Notification androidNotification android
Notification android
 

Similar to 4.C#

06 win forms
06 win forms06 win forms
06 win forms
mrjw
 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
EliasPetros
 
unit 4.docx
unit 4.docxunit 4.docx
unit 4.docx
Sadhana Sreekanth
 
Visual basic concepts
Visual basic conceptsVisual basic concepts
Visual basic concepts
melody77776
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
Dr. C.V. Suresh Babu
 
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
AOmaAli
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
JOSEPHINEA6
 
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.ppt
BhuvanaR13
 
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
scroghamtressie
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introductionbloodyedge03
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Ujwala Junghare
 

Similar to 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
 
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
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
 

More from Raghu nath

Mongo db
Mongo dbMongo db
Mongo db
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
 

More from 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
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

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.