SlideShare uma empresa Scribd logo
1 de 62
Chapter 3 C# Windows Forms
Your first C# Windows Form
IDE: Code Editor and Property Window Code Editor Missing: how to get it back? Property Window Missing: how to get it back?
Your first C# Windows Form Program.cs Form1.cs
Program.cs Window Applications allow multi-threading Single Threaded Apartment [STAThread] Multi Thread Apartment [MTAThread] [STAThread]            // Attribute for Main() method        static void Main() Application.Run(new Form1()); // Begins running a standard                                              // application on the current                                              // thread
Threaded Application
IDE: Form1.cs Form1.cs: code, design and design code Logic codes Form Designer Designer codes
IDE: Form1.cs Contain the logic you put in How to view this panel? In solution explorer: Double-click Form1.cs Menu: View > code   OR   click on [view code icon]
IDE: Form1.cs Contain the code representing the form design Normally, do NOT modify How to view this panel? In solution explorer: Double-click on Form1.Designer.cs
IDE: Form1.cs Contain the form design How to view this panel? In solution explorer: Double-click Form1.cs
Toolbar How to find this window? Menu: View > Toolbar If AutoHide is set    Then Toolbar is usually hide on the left    Just hover your mouse over the hidden Tooblar and reset AutoHide
Toolbar Toolbar window is Context sensitive It will show the controls ONLY in the Design View:  Eg Form1.cs [Design]
Toolbar Categories: ,[object Object]
Common ControlsAnd others Use All Windows Forms to search for unknown Use Common Controls for normal usage
Properties Window How to view Properties Window? Menu: View > Properties Window The properties Window usually on the Bottom Right side
Properties Window Name of Control Sort by category Sort from A to Z Properties Event Property page: available when solution or project is selected
Properties Window Properties     Try changing the Text property from “Form1” to “First WinForm App” Click on Form1 and type over
Properties Window Events     Shows all the events available for this control Try add logic for Form1 Load event by double-clicking on “Load”
Properties Window Add the following codes into the Form1 Load event: Build and run the application
Adding Common Controls Three types of Common Control Display : 	Eg Label Input : 		Eg Textbox, Button Output: 	Eg Label
Button with its Click Event In Form1.cs [Design] view From the Toolbar, drag a button onto the form  OR double-click on button Drag the button to the centre of the form
Button with its Click Event Go to Button Click event code: Double-click on                            OR Select button1, Click on       Icon, then double-clicking on Click event
Button with its Click Event Add the following codes into the button1 Click event: Build and run the application, then click on the button
Exercise 3.1 Make use of Button control, its Click event and output to Message Box For those with textbook: page 28 - 51 For those without textbook           http://alturl.com/uiak       Your First C# Windows Form     Adding Controls to a Blank C# Form     Properties of a C# Control     Adding C# Code to a Button
Next Lesson More controls and problem solving exercises
Recap A new Windows Forms Application has 2 *.cs files ?.cs ?.cs What are these two files?
Recap Program.cs Different from Console Program:  threaded and use Application.Run() method to start a new Form Form1.cs Consists of 3 parts What does each part consist of?
Recap Form1 consisting of 3 views: What does each use for: Form1.cs? Form1.cs [Design]? Form1.Designer.cs?
Recap Windows application with at least one form A form may contain Button TextBox Label … Etc Event driven/activated : program responses to Button Click Mouse Move Keypress
Recap Exercise 3.1:  Button with click event that output a message
Code Behind Microsoft invented “Code Behind” using Partial Class – allows a class to be split into more than 1 file Prior to “Code Behind”- code for logic and design were placed in the same Class file: “Inline”.  “Code Behind” allows logic and design code to be separated Partial class Form1 {          : } Partial class Form1 {          : }
Where to output? For Console Program: using Console.Write() or Console.WriteLine – may still use it for debugging => Output window Two ways to output for Winform Apps Pop up a message box with the output Display the output on controls like label, textbox
How to input? Get inputs from various controls TextBox:  Text property (Eg textBox1.Text) CheckBox: Checked property (Eg checkBox1.Checked) ListBox: SelectedIndex property
Naming Convention for WinForm Underscore is used only with events: eg Form1_Load, button1_Click Do NOT use hungarian  (lblName, btnProcess), but some programmers do use hungarian for GUI controls: Eg a submit button might be btnSubmit, a name label might be lblName – the textbook uses hungarian for GUI controls Alternatively, spell in full: EgbuttonSubmit, labelName (need not know what prefix for which control)
Exercise 3.2 Create the following GUI for Exercise32 Set the TabIndex property     from top to bottom     and from left to right
Containers Controls with Alignments Drag and drop a Container > TabControl to the form Move the tabcontrol to align with the top and left side of form Resize the tabcontrol to align with the bottom and right side of form Set the Anchor property to “Top, Bottom, Left, right”
Containers Controls with Alignments
tabControlvstabPage
Exercise 3.3 Create the GUI for Exercise33: Multiline   textbox
Exercise 3.4 Create the following GUI for exercise34 ReadOnly Multiline   textbox
Where to go from here? MSDN> Windows Forms Programming      > Controls to Use on Windows Forms      > By Function     URL: http://alturl.com/u63m
MSDN: Controls to Use on Windows Forms > By Function
MSDN: Controls to Use on Windows Forms > By Function
MSDN: Controls to Use on Windows Forms > By Function
MSDN: Controls to Use on Windows Forms > By Function
An Example: Web Browser Example: Remarks      The WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. You can use the WebBrowser control, for example, to provide integrated HTML-based user assistance or Web browsing capabilities in your application. Additionally, you can use the WebBrowser control to add your existing Web-based controls to your Windows Forms client applications.
An Example: Web Browser Example      The following code example demonstrates how to implement an address bar for use with the WebBrowser control. This example requires that you have a form that contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.
An Example: Web Browser Create the GUI Program the code (code behind)
Summary Code Behind using Partial Class How to use the Form Designer How to find information on Controls using MSDN Next Lesson:  problem solving Next week: variables and conditional logic
Recap Code Behind using Partial Class How to use the Form Designer How to find information on Controls using MSDN
Problem Solving Next part of the lesson focus on problem solving with the same set of questions from the console program
Problem solving Recall: Console Program for Exercise 2.1        Your Input: 3        Output: 3  3  3  3  3 How do we do for WinForm App?
Guided Handson: Exercise 3.5 Name:  Form1 Text:     Exercise 3.5 Name: textBoxInput Text:     blank TabIndex: 0 Name: textBoxOutput MultiLine: True ReadOnly: True TabIndex: 9 Name: buttonProcess Text:     Process TabIndex: 1
Guided Handson: Exercise 3.5 Double click on [Process] button and add code to  buttonProcess_Click event:       string input;                             // Declare 2 string var       string output;       input = textBoxInput.Text; // Get input string                                                             // Set output string       output = input + “ “ + input + “ “ + input + “ “ +                          input + “ “ + input ; textBoxOutput.Text = output;  // Set onto screen
Guided Handson: Exercise 3.5 Output:
Exercise 3.6     Write a program that asks the user to type the width and the length of a rectangle and then outputs to the screen the area and the perimeter of that rectangle. 	Hint: 1) Assume that the width and length                     are integers                 2) Convert from string to integer:                       use int.Parse( … )                 3) Convert from integer to string:                      use  .ToString() => Next page for screen output
Exercise 3.6 Output:
Exercise 3.7      Write a program that asks the user to type 2 integers n1 and n2 and exchange the value of n1 and n2 if n1 is greater than n2.     Hint:1) To swop 2 variable, you need  another                      variable (n3) to store one of the value                2) Eg                     if (n1 > n2)                     {                         n3 = n2;                         n2 = n1;                         n1 = n3;                     }   “then” processing
Exercise 3.7 Output:
Exercise 3.8 Prompt user to key in 3 integers. Sort the integers in ascending order. Print the 3 integers as you sort. Prompt user to key in 3 integers. Sort the integers in ascending order. Print the 3 integers as you sort.   Input1: 2   Input2: 1   Input3: 0   210   120   102   012 if (n1 > n2) { … } if (n2 > n3) { … } if (n1 > n2) { … } Use this to append output: output = output + n1 + " " + n2 + " " + n3 + “";
Exercise 3.8 Output:
Exercise 3.9 Using the information from MSDN: GUI and codes, design a simple but interesting application.   After you have completed, screen capture the application and paste into a word document.   In the reference section, list the resources you have used.     MSDN> Windows Forms Programming      > Controls to Use on Windows Forms      > By Function     URL: http://alturl.com/u63m

Mais conteúdo relacionado

Mais procurados

Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vb
Amandeep Kaur
 
Toolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbToolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vb
Amandeep Kaur
 

Mais procurados (20)

Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Vs c# lecture1
Vs c# lecture1Vs c# lecture1
Vs c# lecture1
 
Controls events
Controls eventsControls events
Controls events
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vb
 
Active x control
Active x controlActive x control
Active x control
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Vs c# lecture3
Vs c# lecture3Vs c# lecture3
Vs c# lecture3
 
4.7.14&17.7.14&23.6.15&10.9.15
4.7.14&17.7.14&23.6.15&10.9.154.7.14&17.7.14&23.6.15&10.9.15
4.7.14&17.7.14&23.6.15&10.9.15
 
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
 
Vs c# lecture5
Vs c# lecture5Vs c# lecture5
Vs c# lecture5
 
Buttons In .net Visual Basic
Buttons In .net Visual BasicButtons In .net Visual Basic
Buttons In .net Visual Basic
 
Class viii ch-7 visual basic 2008
Class  viii ch-7 visual basic 2008Class  viii ch-7 visual basic 2008
Class viii ch-7 visual basic 2008
 
Vs c# lecture2
Vs c# lecture2Vs c# lecture2
Vs c# lecture2
 
Vs c# lecture4
Vs c# lecture4Vs c# lecture4
Vs c# lecture4
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
100 keyboard shortcuts for windows 8
100 keyboard shortcuts for windows 8100 keyboard shortcuts for windows 8
100 keyboard shortcuts for windows 8
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menu
 
Toolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbToolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vb
 

Destaque

12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17
Niit Care
 
c# events, delegates and lambdas
c# events, delegates and lambdasc# events, delegates and lambdas
c# events, delegates and lambdas
Fernando Galvan
 
Java event processing model in c# and java
Java  event processing model in c# and javaJava  event processing model in c# and java
Java event processing model in c# and java
Tech_MX
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
Jussi Pohjolainen
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
2.1 zaman air batu dan zaman prasejarah
2.1 zaman air batu dan zaman prasejarah2.1 zaman air batu dan zaman prasejarah
2.1 zaman air batu dan zaman prasejarah
firo HAR
 

Destaque (20)

Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Objective C Primer (with ref to C#)
Objective C  Primer (with ref to C#)Objective C  Primer (with ref to C#)
Objective C Primer (with ref to C#)
 
Revision exercises on loop
Revision exercises on loopRevision exercises on loop
Revision exercises on loop
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
 
Inglish iii
Inglish iiiInglish iii
Inglish iii
 
Ingles
InglesIngles
Ingles
 
12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17
 
[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms Controls[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms Controls
 
c# events, delegates and lambdas
c# events, delegates and lambdasc# events, delegates and lambdas
c# events, delegates and lambdas
 
Java event processing model in c# and java
Java  event processing model in c# and javaJava  event processing model in c# and java
Java event processing model in c# and java
 
Ch01
Ch01Ch01
Ch01
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
PPPM BAHASA INGGERIS TINGKATAN 1
PPPM BAHASA INGGERIS TINGKATAN 1PPPM BAHASA INGGERIS TINGKATAN 1
PPPM BAHASA INGGERIS TINGKATAN 1
 
Intro++ to C#
Intro++ to C#Intro++ to C#
Intro++ to C#
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
2.1 zaman air batu dan zaman prasejarah
2.1 zaman air batu dan zaman prasejarah2.1 zaman air batu dan zaman prasejarah
2.1 zaman air batu dan zaman prasejarah
 
Sejarah Tingkatan 1: Bab 2 ZAMAN PRA SEJARAH
Sejarah Tingkatan 1: Bab 2 ZAMAN PRA SEJARAHSejarah Tingkatan 1: Bab 2 ZAMAN PRA SEJARAH
Sejarah Tingkatan 1: Bab 2 ZAMAN PRA SEJARAH
 
Nota lengkap sejarah tingkatan 1
Nota lengkap sejarah tingkatan 1Nota lengkap sejarah tingkatan 1
Nota lengkap sejarah tingkatan 1
 

Semelhante a Spf chapter 03 WinForm

Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
dhi her
 
Gui builder
Gui builderGui builder
Gui builder
learnt
 
03 intro to vb programming
03 intro to vb programming03 intro to vb programming
03 intro to vb programming
Jomel Penalba
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
ashhadiqbal
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
bloodyedge03
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
dhi her
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
jayguyab
 

Semelhante a Spf chapter 03 WinForm (20)

Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
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
 
06 win forms
06 win forms06 win forms
06 win forms
 
Gui builder
Gui builderGui builder
Gui builder
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Vb%20 tutorial
Vb%20 tutorialVb%20 tutorial
Vb%20 tutorial
 
03 intro to vb programming
03 intro to vb programming03 intro to vb programming
03 intro to vb programming
 
Chapter03 Ppt
Chapter03 PptChapter03 Ppt
Chapter03 Ppt
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 

Mais de Hock Leng PUAH

CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 

Mais de Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker Students
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Spf chapter 03 WinForm

  • 1. Chapter 3 C# Windows Forms
  • 2. Your first C# Windows Form
  • 3. IDE: Code Editor and Property Window Code Editor Missing: how to get it back? Property Window Missing: how to get it back?
  • 4. Your first C# Windows Form Program.cs Form1.cs
  • 5. Program.cs Window Applications allow multi-threading Single Threaded Apartment [STAThread] Multi Thread Apartment [MTAThread] [STAThread] // Attribute for Main() method static void Main() Application.Run(new Form1()); // Begins running a standard // application on the current // thread
  • 7. IDE: Form1.cs Form1.cs: code, design and design code Logic codes Form Designer Designer codes
  • 8. IDE: Form1.cs Contain the logic you put in How to view this panel? In solution explorer: Double-click Form1.cs Menu: View > code OR click on [view code icon]
  • 9. IDE: Form1.cs Contain the code representing the form design Normally, do NOT modify How to view this panel? In solution explorer: Double-click on Form1.Designer.cs
  • 10. IDE: Form1.cs Contain the form design How to view this panel? In solution explorer: Double-click Form1.cs
  • 11. Toolbar How to find this window? Menu: View > Toolbar If AutoHide is set Then Toolbar is usually hide on the left Just hover your mouse over the hidden Tooblar and reset AutoHide
  • 12. Toolbar Toolbar window is Context sensitive It will show the controls ONLY in the Design View: Eg Form1.cs [Design]
  • 13.
  • 14. Common ControlsAnd others Use All Windows Forms to search for unknown Use Common Controls for normal usage
  • 15. Properties Window How to view Properties Window? Menu: View > Properties Window The properties Window usually on the Bottom Right side
  • 16. Properties Window Name of Control Sort by category Sort from A to Z Properties Event Property page: available when solution or project is selected
  • 17. Properties Window Properties Try changing the Text property from “Form1” to “First WinForm App” Click on Form1 and type over
  • 18. Properties Window Events Shows all the events available for this control Try add logic for Form1 Load event by double-clicking on “Load”
  • 19. Properties Window Add the following codes into the Form1 Load event: Build and run the application
  • 20. Adding Common Controls Three types of Common Control Display : Eg Label Input : Eg Textbox, Button Output: Eg Label
  • 21. Button with its Click Event In Form1.cs [Design] view From the Toolbar, drag a button onto the form OR double-click on button Drag the button to the centre of the form
  • 22. Button with its Click Event Go to Button Click event code: Double-click on OR Select button1, Click on Icon, then double-clicking on Click event
  • 23. Button with its Click Event Add the following codes into the button1 Click event: Build and run the application, then click on the button
  • 24. Exercise 3.1 Make use of Button control, its Click event and output to Message Box For those with textbook: page 28 - 51 For those without textbook http://alturl.com/uiak Your First C# Windows Form Adding Controls to a Blank C# Form Properties of a C# Control Adding C# Code to a Button
  • 25. Next Lesson More controls and problem solving exercises
  • 26. Recap A new Windows Forms Application has 2 *.cs files ?.cs ?.cs What are these two files?
  • 27. Recap Program.cs Different from Console Program: threaded and use Application.Run() method to start a new Form Form1.cs Consists of 3 parts What does each part consist of?
  • 28. Recap Form1 consisting of 3 views: What does each use for: Form1.cs? Form1.cs [Design]? Form1.Designer.cs?
  • 29. Recap Windows application with at least one form A form may contain Button TextBox Label … Etc Event driven/activated : program responses to Button Click Mouse Move Keypress
  • 30. Recap Exercise 3.1: Button with click event that output a message
  • 31. Code Behind Microsoft invented “Code Behind” using Partial Class – allows a class to be split into more than 1 file Prior to “Code Behind”- code for logic and design were placed in the same Class file: “Inline”. “Code Behind” allows logic and design code to be separated Partial class Form1 { : } Partial class Form1 { : }
  • 32. Where to output? For Console Program: using Console.Write() or Console.WriteLine – may still use it for debugging => Output window Two ways to output for Winform Apps Pop up a message box with the output Display the output on controls like label, textbox
  • 33. How to input? Get inputs from various controls TextBox: Text property (Eg textBox1.Text) CheckBox: Checked property (Eg checkBox1.Checked) ListBox: SelectedIndex property
  • 34. Naming Convention for WinForm Underscore is used only with events: eg Form1_Load, button1_Click Do NOT use hungarian (lblName, btnProcess), but some programmers do use hungarian for GUI controls: Eg a submit button might be btnSubmit, a name label might be lblName – the textbook uses hungarian for GUI controls Alternatively, spell in full: EgbuttonSubmit, labelName (need not know what prefix for which control)
  • 35. Exercise 3.2 Create the following GUI for Exercise32 Set the TabIndex property from top to bottom and from left to right
  • 36. Containers Controls with Alignments Drag and drop a Container > TabControl to the form Move the tabcontrol to align with the top and left side of form Resize the tabcontrol to align with the bottom and right side of form Set the Anchor property to “Top, Bottom, Left, right”
  • 39. Exercise 3.3 Create the GUI for Exercise33: Multiline textbox
  • 40. Exercise 3.4 Create the following GUI for exercise34 ReadOnly Multiline textbox
  • 41. Where to go from here? MSDN> Windows Forms Programming > Controls to Use on Windows Forms > By Function URL: http://alturl.com/u63m
  • 42. MSDN: Controls to Use on Windows Forms > By Function
  • 43. MSDN: Controls to Use on Windows Forms > By Function
  • 44. MSDN: Controls to Use on Windows Forms > By Function
  • 45. MSDN: Controls to Use on Windows Forms > By Function
  • 46. An Example: Web Browser Example: Remarks The WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. You can use the WebBrowser control, for example, to provide integrated HTML-based user assistance or Web browsing capabilities in your application. Additionally, you can use the WebBrowser control to add your existing Web-based controls to your Windows Forms client applications.
  • 47. An Example: Web Browser Example The following code example demonstrates how to implement an address bar for use with the WebBrowser control. This example requires that you have a form that contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.
  • 48. An Example: Web Browser Create the GUI Program the code (code behind)
  • 49. Summary Code Behind using Partial Class How to use the Form Designer How to find information on Controls using MSDN Next Lesson: problem solving Next week: variables and conditional logic
  • 50. Recap Code Behind using Partial Class How to use the Form Designer How to find information on Controls using MSDN
  • 51. Problem Solving Next part of the lesson focus on problem solving with the same set of questions from the console program
  • 52. Problem solving Recall: Console Program for Exercise 2.1 Your Input: 3 Output: 3 3 3 3 3 How do we do for WinForm App?
  • 53. Guided Handson: Exercise 3.5 Name: Form1 Text: Exercise 3.5 Name: textBoxInput Text: blank TabIndex: 0 Name: textBoxOutput MultiLine: True ReadOnly: True TabIndex: 9 Name: buttonProcess Text: Process TabIndex: 1
  • 54. Guided Handson: Exercise 3.5 Double click on [Process] button and add code to buttonProcess_Click event: string input; // Declare 2 string var string output; input = textBoxInput.Text; // Get input string // Set output string output = input + “ “ + input + “ “ + input + “ “ + input + “ “ + input ; textBoxOutput.Text = output; // Set onto screen
  • 56. Exercise 3.6 Write a program that asks the user to type the width and the length of a rectangle and then outputs to the screen the area and the perimeter of that rectangle. Hint: 1) Assume that the width and length are integers 2) Convert from string to integer: use int.Parse( … ) 3) Convert from integer to string: use .ToString() => Next page for screen output
  • 58. Exercise 3.7 Write a program that asks the user to type 2 integers n1 and n2 and exchange the value of n1 and n2 if n1 is greater than n2. Hint:1) To swop 2 variable, you need another variable (n3) to store one of the value 2) Eg if (n1 > n2) { n3 = n2; n2 = n1; n1 = n3; } “then” processing
  • 60. Exercise 3.8 Prompt user to key in 3 integers. Sort the integers in ascending order. Print the 3 integers as you sort. Prompt user to key in 3 integers. Sort the integers in ascending order. Print the 3 integers as you sort. Input1: 2 Input2: 1 Input3: 0 210 120 102 012 if (n1 > n2) { … } if (n2 > n3) { … } if (n1 > n2) { … } Use this to append output: output = output + n1 + " " + n2 + " " + n3 + “";
  • 62. Exercise 3.9 Using the information from MSDN: GUI and codes, design a simple but interesting application. After you have completed, screen capture the application and paste into a word document. In the reference section, list the resources you have used. MSDN> Windows Forms Programming > Controls to Use on Windows Forms > By Function URL: http://alturl.com/u63m
  • 63. Summary WinForm App Form1.cs and Program.cs (main() is threaded and use Application.Run to start FORM1) GUI design using Toolbar Controls Event activation – eg Button Click Problem solving – same as what we did in console program