SlideShare une entreprise Scribd logo
1  sur  49
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
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
Output Try relating to console program using Console.Write() or WriteLine() Two ways to output for Winform Apps Pop up a message box with the output Display the output on controls like label, textbox
Input Get inputs from various controls TextBox:  Text property (Eg textBox1.Text) CheckBox: Checked property (Eg checkBox1.Checked) ListBox: SelectedIndex property  Where to find more information:                             http://alturl.com/e94q
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)
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:

Contenu connexe

Tendances

Session 1. Bai 1 ve winform
Session 1. Bai 1 ve winformSession 1. Bai 1 ve winform
Session 1. Bai 1 ve winform
mrtom16071980
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
Salim M
 
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
 

Tendances (20)

Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)Windows form application_in_vb(vb.net --3 year)
Windows form application_in_vb(vb.net --3 year)
 
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
 
Buttons In .net Visual Basic
Buttons In .net Visual BasicButtons In .net Visual Basic
Buttons In .net Visual Basic
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Session 1. Bai 1 ve winform
Session 1. Bai 1 ve winformSession 1. Bai 1 ve winform
Session 1. Bai 1 ve winform
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
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
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Common dialog control
Common dialog controlCommon dialog control
Common dialog control
 
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
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Computer homework
Computer homeworkComputer homework
Computer homework
 
Toolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbToolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vb
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2
 

En vedette

En vedette (10)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 Variables
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 

Similaire à SPF WinForm Programs

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 i lab 4 of 6
Cis 355 i lab 4 of 6Cis 355 i lab 4 of 6
Cis 355 i lab 4 of 6
helpido9
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
comp274
 
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
 

Similaire à SPF WinForm Programs (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
 
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
 
Csphtp1 03
Csphtp1 03Csphtp1 03
Csphtp1 03
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
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 i lab 4 of 6
Cis 355 i lab 4 of 6Cis 355 i lab 4 of 6
Cis 355 i lab 4 of 6
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
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
 
2621008 - C++ 1
2621008 -  C++ 12621008 -  C++ 1
2621008 - C++ 1
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 

Plus 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
 

Plus de Hock Leng PUAH (20)

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
 
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
 
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
 
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#)
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

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.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
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
 

SPF WinForm Programs

  • 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. Exercise 3.2 Create the following GUI for Exercise32 Set the TabIndex property from top to bottom and from left to right
  • 32. 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”
  • 35. Exercise 3.3 Create the GUI for Exercise33: Multiline textbox
  • 36. Exercise 3.4 Create the following GUI for exercise34 ReadOnly Multiline textbox
  • 37. Output Try relating to console program using Console.Write() or WriteLine() Two ways to output for Winform Apps Pop up a message box with the output Display the output on controls like label, textbox
  • 38. Input Get inputs from various controls TextBox: Text property (Eg textBox1.Text) CheckBox: Checked property (Eg checkBox1.Checked) ListBox: SelectedIndex property Where to find more information: http://alturl.com/e94q
  • 39. 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)
  • 40. 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?
  • 41. 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
  • 42. 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
  • 44. 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
  • 46. 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
  • 48. 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 + “";
  • 50. 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