SlideShare a Scribd company logo
Chapter 3C# Windows Forms
Your first C# Windows Form
IDE: Code Editor and Property WindowCode Editor Missing: how to get it back?Property Window Missing: how to get it back?
Your first C# Windows FormProgram.csForm1.cs
Program.csWindow Applications allow multi-threadingSingle 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.csForm1.cs: code, design and design codeLogic codesForm DesignerDesigner codes
IDE: Form1.csContain the logic you put inHow to view this panel?In solution explorer: Double-click Form1.csMenu: View > code   OR   click on [view code icon]
IDE: Form1.csContain the code representing the form designNormally, do NOT modifyHow to view this panel?In solution explorer: Double-click on Form1.Designer.cs
IDE: Form1.csContain the form designHow to view this panel?In solution explorer: Double-click Form1.cs
ToolbarHow to find this window?Menu: View > ToolbarIf AutoHide is set   Then Toolbar is usually hide on the left   Just hover your mouse over the hiddenTooblar and reset AutoHide
ToolbarToolbar window is Context sensitiveIt will show the controls ONLY in the Design View:  Eg Form1.cs [Design]
ToolbarCategories:All Windows Forms
Common ControlsAnd othersUse All Windows Formsto search for unknownUse Common Controlsfor normal usage
Properties WindowHow to view Properties Window?Menu: View > Properties WindowThe properties Window usually on the Bottom Right side
Properties WindowName of ControlSort by categorySort from A to ZPropertiesEventProperty page: available when solution or project is selected
Properties WindowProperties    Try changing the Text property from “Form1” to “First WinForm App”Click on Form1 and type over
Properties WindowEvents    Shows all the events available for this controlTry add logic for Form1 Load event by double-clicking on “Load”
Properties WindowAdd the following codes into the Form1 Load event:Build and run the application
Adding Common ControlsThree types of Common ControlDisplay : 	Eg LabelInput : 		Eg Textbox, ButtonOutput: 	Eg Label
Button with its Click EventIn Form1.cs [Design] viewFrom the Toolbar, drag a button onto the form  OR double-click on buttonDrag the button to the centre of the form
Button with its Click EventGo to Button Click event code:Double-click on                            ORSelect button1, Click on       Icon, then double-clicking on Click event
Button with its Click EventAdd the following codes into the button1 Click event:Build and run the application, then click on the button
Exercise 3.1Make use of Button control, its Click event and output to Message BoxFor those with textbook: page 28 - 51For 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 LessonMore controls and problem solving exercises
RecapA new Windows Forms Application has 2 *.cs files?.cs?.csWhat are these two files?
RecapProgram.csDifferent from Console Program:  threaded and use Application.Run() method to start a new FormForm1.csConsists of 3 partsWhat does each part consist of?
RecapForm1 consisting of 3 views:What does each use for:Form1.cs?Form1.cs [Design]?Form1.Designer.cs?
RecapWindows application with at least one formA form may containButtonTextBoxLabel… EtcEvent driven/activated : program responses toButton ClickMouse MoveKeypress
RecapExercise 3.1:  Button with click event that output a message
Code BehindMicrosoft invented “Code Behind” using Partial Class – allows a class to be split into more than 1 filePrior 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 separatedPartial class Form1{         :}Partial class Form1{         :}
Where to output?For Console Program: using Console.Write() or Console.WriteLine – may still use it for debugging => Output windowTwo ways to output for Winform AppsPop up a message box with the outputDisplay the output on controls like label, textbox
How to input?Get inputs from various controlsTextBox:  Text property (Eg textBox1.Text)CheckBox: Checked property (Eg checkBox1.Checked)ListBox: SelectedIndex property
Naming Convention for WinFormUnderscore is used only with events: eg Form1_Load, button1_ClickDo 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 controlsAlternatively, spell in full: EgbuttonSubmit, labelName (need not know what prefix for which control)
Exercise 3.2Create the following GUI for Exercise32Set the TabIndex property    from top to bottom    and from left to right
Containers Controls with AlignmentsDrag and drop a Container > TabControl to the formMove the tabcontrol to align with the top and left side of formResize the tabcontrol to align with the bottom and right side of formSet the Anchor property to “Top, Bottom, Left, right”
Containers Controls with Alignments
tabControlvstabPage
Exercise 3.3Create the GUI for Exercise33:Multiline   textbox
Exercise 3.4Create the following GUI for exercise34ReadOnly 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 BrowserExample: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 BrowserExample     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 BrowserCreate the GUIProgram the code (code behind)
SummaryCode Behind using Partial ClassHow to use the Form DesignerHow to find information on Controls using MSDNNext Lesson:  problem solvingNext week: variables and conditional logic
RecapCode Behind using Partial ClassHow to use the Form DesignerHow to find information on Controls using MSDN
Problem SolvingNext part of the lesson focus on problem solving with the same set of questions from the console program
Problem solvingRecall: Console Program for Exercise 2.1       Your Input: 3       Output: 3  3  3  3  3How do we do for WinForm App?
Guided Handson: Exercise 3.5Name:  Form1Text:     Exercise 3.5Name: textBoxInputText:     blankTabIndex: 0Name: textBoxOutputMultiLine: TrueReadOnly: TrueTabIndex: 9Name: buttonProcessText:     ProcessTabIndex: 1
Guided Handson: Exercise 3.5Double 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.5Output:
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.6Output:
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.7Output:
Exercise 3.8Prompt 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  012if (n1 > n2) { … }if (n2 > n3) { … }if (n1 > n2) { … }Use this to append output:output = output + n1 + " " + n2 + " " + n3 + “\r\n";
Exercise 3.8Output:
Exercise 3.9Using 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

More Related Content

PPTX
Spf chapter10 events
PDF
Windows Forms For Beginners Part - 1
PDF
Windows Forms For Beginners Part - 4
PPTX
SPF WinForm Programs
PPTX
Windowforms controls c#
PPT
DOCX
Visual C# 2010
PDF
Windows Forms For Beginners Part 5
Spf chapter10 events
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 4
SPF WinForm Programs
Windowforms controls c#
Visual C# 2010
Windows Forms For Beginners Part 5

What's hot (20)

PPTX
Windows form application - C# Training
PDF
Windows Forms For Beginners Part - 3
PPTX
Vs c# lecture1
PPTX
Controls events
PDF
Visual basic asp.net programming introduction
PPTX
Image contro, and format functions in vb
PPT
Active x control
PPTX
Vs c# lecture3
PPT
4.7.14&17.7.14&23.6.15&10.9.15
PPT
Introduction to programming using Visual Basic 6
PPTX
Vs c# lecture5
PPT
Buttons In .net Visual Basic
PPTX
Class viii ch-7 visual basic 2008
PPTX
Vs c# lecture2
PPTX
Vs c# lecture4
PDF
Intake 37 9
PDF
100 keyboard shortcuts for windows 8
PPT
Visual Basic menu
PPTX
Toolbar, statusbar, coolbar in vb
Windows form application - C# Training
Windows Forms For Beginners Part - 3
Vs c# lecture1
Controls events
Visual basic asp.net programming introduction
Image contro, and format functions in vb
Active x control
Vs c# lecture3
4.7.14&17.7.14&23.6.15&10.9.15
Introduction to programming using Visual Basic 6
Vs c# lecture5
Buttons In .net Visual Basic
Class viii ch-7 visual basic 2008
Vs c# lecture2
Vs c# lecture4
Intake 37 9
100 keyboard shortcuts for windows 8
Visual Basic menu
Toolbar, statusbar, coolbar in vb
Ad

Viewers also liked (20)

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

Similar to Spf chapter 03 WinForm (20)

PPTX
LECTURE 12 WINDOWS FORMS PART 2.pptx
PPT
06 win forms
PDF
Creating Windows-based Applications Part-I
PPT
Windows form applicationWindows form application
PDF
PPTX
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PPTX
lesson-9-Building-Windows-Form-Application.pptx
PPS
02 gui 02
PPT
Csphtp1 12
PDF
Content
PDF
Visual Basic IDE Introduction
PDF
Visual Basic IDE Intro.pdf
DOC
Visual basic
PDF
I x scripting
PPT
Csphtp1 03
PDF
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
DOCX
The visual studio start page is shown in the figure below
DOC
Ics4u dayplans
PPT
visual programming GDI presentation powerpoint
PPT
Visual programming Chapter 3: GUI (Graphical User Interface)
LECTURE 12 WINDOWS FORMS PART 2.pptx
06 win forms
Creating Windows-based Applications Part-I
Windows form applicationWindows form application
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
lesson-9-Building-Windows-Form-Application.pptx
02 gui 02
Csphtp1 12
Content
Visual Basic IDE Introduction
Visual Basic IDE Intro.pdf
Visual basic
I x scripting
Csphtp1 03
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
The visual studio start page is shown in the figure below
Ics4u dayplans
visual programming GDI presentation powerpoint
Visual programming Chapter 3: GUI (Graphical User Interface)

More from Hock Leng PUAH (20)

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

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Empowerment Technology for Senior High School Guide
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
RMMM.pdf make it easy to upload and study
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Indian roads congress 037 - 2012 Flexible pavement
IGGE1 Understanding the Self1234567891011
Final Presentation General Medicine 03-08-2024.pptx
UNIT III MENTAL HEALTH NURSING ASSESSMENT
What if we spent less time fighting change, and more time building what’s rig...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Practical Manual AGRO-233 Principles and Practices of Natural Farming
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Complications of Minimal Access Surgery at WLH
Empowerment Technology for Senior High School Guide
Chinmaya Tiranga quiz Grand Finale.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
A powerpoint presentation on the Revised K-10 Science Shaping Paper
RMMM.pdf make it easy to upload and study
History, Philosophy and sociology of education (1).pptx
Orientation - ARALprogram of Deped to the Parents.pptx

Spf chapter 03 WinForm

  • 2. Your first C# Windows Form
  • 3. IDE: Code Editor and Property WindowCode Editor Missing: how to get it back?Property Window Missing: how to get it back?
  • 4. Your first C# Windows FormProgram.csForm1.cs
  • 5. Program.csWindow Applications allow multi-threadingSingle 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.csForm1.cs: code, design and design codeLogic codesForm DesignerDesigner codes
  • 8. IDE: Form1.csContain the logic you put inHow to view this panel?In solution explorer: Double-click Form1.csMenu: View > code OR click on [view code icon]
  • 9. IDE: Form1.csContain the code representing the form designNormally, do NOT modifyHow to view this panel?In solution explorer: Double-click on Form1.Designer.cs
  • 10. IDE: Form1.csContain the form designHow to view this panel?In solution explorer: Double-click Form1.cs
  • 11. ToolbarHow to find this window?Menu: View > ToolbarIf AutoHide is set Then Toolbar is usually hide on the left Just hover your mouse over the hiddenTooblar and reset AutoHide
  • 12. ToolbarToolbar window is Context sensitiveIt will show the controls ONLY in the Design View: Eg Form1.cs [Design]
  • 14. Common ControlsAnd othersUse All Windows Formsto search for unknownUse Common Controlsfor normal usage
  • 15. Properties WindowHow to view Properties Window?Menu: View > Properties WindowThe properties Window usually on the Bottom Right side
  • 16. Properties WindowName of ControlSort by categorySort from A to ZPropertiesEventProperty page: available when solution or project is selected
  • 17. Properties WindowProperties Try changing the Text property from “Form1” to “First WinForm App”Click on Form1 and type over
  • 18. Properties WindowEvents Shows all the events available for this controlTry add logic for Form1 Load event by double-clicking on “Load”
  • 19. Properties WindowAdd the following codes into the Form1 Load event:Build and run the application
  • 20. Adding Common ControlsThree types of Common ControlDisplay : Eg LabelInput : Eg Textbox, ButtonOutput: Eg Label
  • 21. Button with its Click EventIn Form1.cs [Design] viewFrom the Toolbar, drag a button onto the form OR double-click on buttonDrag the button to the centre of the form
  • 22. Button with its Click EventGo to Button Click event code:Double-click on ORSelect button1, Click on Icon, then double-clicking on Click event
  • 23. Button with its Click EventAdd the following codes into the button1 Click event:Build and run the application, then click on the button
  • 24. Exercise 3.1Make use of Button control, its Click event and output to Message BoxFor those with textbook: page 28 - 51For 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 LessonMore controls and problem solving exercises
  • 26. RecapA new Windows Forms Application has 2 *.cs files?.cs?.csWhat are these two files?
  • 27. RecapProgram.csDifferent from Console Program: threaded and use Application.Run() method to start a new FormForm1.csConsists of 3 partsWhat does each part consist of?
  • 28. RecapForm1 consisting of 3 views:What does each use for:Form1.cs?Form1.cs [Design]?Form1.Designer.cs?
  • 29. RecapWindows application with at least one formA form may containButtonTextBoxLabel… EtcEvent driven/activated : program responses toButton ClickMouse MoveKeypress
  • 30. RecapExercise 3.1: Button with click event that output a message
  • 31. Code BehindMicrosoft invented “Code Behind” using Partial Class – allows a class to be split into more than 1 filePrior 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 separatedPartial 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 windowTwo ways to output for Winform AppsPop up a message box with the outputDisplay the output on controls like label, textbox
  • 33. How to input?Get inputs from various controlsTextBox: Text property (Eg textBox1.Text)CheckBox: Checked property (Eg checkBox1.Checked)ListBox: SelectedIndex property
  • 34. Naming Convention for WinFormUnderscore is used only with events: eg Form1_Load, button1_ClickDo 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 controlsAlternatively, spell in full: EgbuttonSubmit, labelName (need not know what prefix for which control)
  • 35. Exercise 3.2Create the following GUI for Exercise32Set the TabIndex property from top to bottom and from left to right
  • 36. Containers Controls with AlignmentsDrag and drop a Container > TabControl to the formMove the tabcontrol to align with the top and left side of formResize the tabcontrol to align with the bottom and right side of formSet the Anchor property to “Top, Bottom, Left, right”
  • 39. Exercise 3.3Create the GUI for Exercise33:Multiline textbox
  • 40. Exercise 3.4Create the following GUI for exercise34ReadOnly 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 BrowserExample: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 BrowserExample 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 BrowserCreate the GUIProgram the code (code behind)
  • 49. SummaryCode Behind using Partial ClassHow to use the Form DesignerHow to find information on Controls using MSDNNext Lesson: problem solvingNext week: variables and conditional logic
  • 50. RecapCode Behind using Partial ClassHow to use the Form DesignerHow to find information on Controls using MSDN
  • 51. Problem SolvingNext part of the lesson focus on problem solving with the same set of questions from the console program
  • 52. Problem solvingRecall: Console Program for Exercise 2.1 Your Input: 3 Output: 3 3 3 3 3How do we do for WinForm App?
  • 53. Guided Handson: Exercise 3.5Name: Form1Text: Exercise 3.5Name: textBoxInputText: blankTabIndex: 0Name: textBoxOutputMultiLine: TrueReadOnly: TrueTabIndex: 9Name: buttonProcessText: ProcessTabIndex: 1
  • 54. Guided Handson: Exercise 3.5Double 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.8Prompt 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 012if (n1 > n2) { … }if (n2 > n3) { … }if (n1 > n2) { … }Use this to append output:output = output + n1 + " " + n2 + " " + n3 + “\r\n";
  • 62. Exercise 3.9Using 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. SummaryWinForm AppForm1.cs andProgram.cs (main() is threaded and use Application.Run to start FORM1)GUI design using Toolbar ControlsEvent activation – eg Button ClickProblem solving – same as what we did in console program