SlideShare a Scribd company logo
1 of 5
Download to read offline
Demo Project:
• Complex Calculator
What will you learn?
• Adding single event handlers
• Identifying from which button handler is called.
• Using flag variable to write smart
Windows Forms for Beginners
www.dotnetvideotutorial.com
single event handlers for Multiple Buttons
dentifying from which button handler is called.
Using flag variable to write smart code.
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
Part 4
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
www.dotnetvideotutorial.com
Demo Project 1: Complex Calculator
Step 1: Design UI:
Instructions:
• When clicked on any number button that number should get displayed on label
lblDisplay.
• As all numeric buttons have same functionality we will add single handler
Digit_Click for click event of all numeric buttons
Label:
Name: lblDisplay
AutoSize: False
BackColor: White
BorderStyle: FixedSingle
Text: Blank
TextAlign: MiddleRight
Form:
Name: frmCalculator
Text: Calculator
18 Buttons:
Text: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
., C, +, -, *, /, =, OFF
Name: Name accordingly for
example btn1, btnPlus,
btnOFF, etc
2 Group Boxes:
Text: Blank
www.dotnetvideotutorial.com
• As all operator buttons have same functionality we will add single handler
Operator_Click for click event of all operator buttons
Step 2: Adding event handlers
1. Right click on form Click View code.
2. In class frmCalculator Declare following variables
public partial class frmCalculator : Form
{
double no1, no2, result;
string op;
bool flg;
…..
}
3. Insert single event handler for all numeric buttons.
• First Select number 1 button (btn1)
• Press Control key and then select all number buttons
• Go to property window Switch to event view by clicking light sign (see
image below: pointed by Event Button call out) Locate Click event
Type “Digits_Click” Press enter and handler will be inserted
Events Button
Click Event
All number
buttons are
selected
www.dotnetvideotutorial.com
4. In Digits_Click() handler write following code
private void Digits_Click(object sender, EventArgs e)
{
if (flg == true)
{
lblDisplay.Text = "";
flg = false;
}
Button btn = (Button)sender;
lblDisplay.Text += btn.Text;
}
5. Insert single event handler for all operator buttons
• Select Plus button then press control key and select Minus, Multiplication
and Division buttons.
• Do not select Equal (=) button
• Go to property window Events list Locate Click event and type
“Operator_Click()” and press enter. code it as follow
private void Operator_Click(object sender, EventArgs e)
{
no1 = Convert.ToInt32(lblDisplay.Text);
op = ((Button)sender).Text;
flg = true;
}
6. Double click on equal button and insert following code
private void btnEqual_Click(object sender, EventArgs e)
{
no2 = Convert.ToDouble(lblDisplay.Text);
switch (op)
{
case "+":
result = no1 + no2;
break;
case "-":
result = no1 - no2;
break;
case "*":
result = no1 * no2;
break;
case "/":
www.dotnetvideotutorial.com
result = no1 / no2;
break;
}
lblDisplay.Text = result.ToString();
flg = true;
}
7. Double click on point button
private void btnPoint_Click(object sender, EventArgs e)
{
if(! lblDisplay.Text.Contains("."))
lblDisplay.Text += ".";
}
8. Clear button
private void btnClear_Click(object sender, EventArgs e)
{
no1 = 0;
no2 = 0;
result = 0;
lblDisplay.Text = "";
}
9. OFF button
private void btnOFF_Click(object sender, EventArgs e)
{
Application.Exit();
}
10.Execute and test.
11.Debug step by step using F11 to understand logic

More Related Content

What's hot (20)

06 win forms
06 win forms06 win forms
06 win forms
 
Vs c# lecture1
Vs c# lecture1Vs c# lecture1
Vs c# lecture1
 
Spf chapter10 events
Spf chapter10 eventsSpf chapter10 events
Spf chapter10 events
 
Controls events
Controls eventsControls events
Controls events
 
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)
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
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
 
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
 
Vs c# lecture3
Vs c# lecture3Vs c# lecture3
Vs c# lecture3
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.net
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
visual basic programming
visual basic programmingvisual basic programming
visual basic programming
 
Vs c# lecture2
Vs c# lecture2Vs c# lecture2
Vs c# lecture2
 
Vs c# lecture4
Vs c# lecture4Vs c# lecture4
Vs c# lecture4
 
Vs c# lecture5
Vs c# lecture5Vs c# lecture5
Vs c# lecture5
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Session 1. Bai 1 ve winform
Session 1. Bai 1 ve winformSession 1. Bai 1 ve winform
Session 1. Bai 1 ve winform
 

Viewers also liked

c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application veera
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Bhushan Mulmule
 
กำหนดค่า Link label
กำหนดค่า Link labelกำหนดค่า Link label
กำหนดค่า Link labelNaruemon Soonthong
 
Setup Project in Visual Studio C#
Setup Project in Visual Studio C#Setup Project in Visual Studio C#
Setup Project in Visual Studio C#Naruemon Soonthong
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To DotnetSAMIR BHOGAYTA
 

Viewers also liked (9)

c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
กำหนดค่า Link label
กำหนดค่า Link labelกำหนดค่า Link label
กำหนดค่า Link label
 
Setup Project in Visual Studio C#
Setup Project in Visual Studio C#Setup Project in Visual Studio C#
Setup Project in Visual Studio C#
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
 
Ch2 ar
Ch2 arCh2 ar
Ch2 ar
 
ASP
ASPASP
ASP
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
 

Similar to Windows Forms For Beginners Part - 4

Windows Virtual Keyboard modification
Windows Virtual Keyboard modificationWindows Virtual Keyboard modification
Windows Virtual Keyboard modificationtopomax
 
How support caller ID phone number
How support caller ID phone numberHow support caller ID phone number
How support caller ID phone numbertopomax
 
3.4 events and interactivity
3.4   events and interactivity3.4   events and interactivity
3.4 events and interactivityallenbailey
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2kshyju
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfYOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfrajkumarm401
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxkeshayoon3mu
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxAOmaAli
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityGilbert Guerrero
 
How support caller Id phone number with a modem
How support caller Id phone number with a modemHow support caller Id phone number with a modem
How support caller Id phone number with a modemtopomax
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Designpatf719
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...bhargavi804095
 
follow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightfollow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightQIRIS
 
Introduction to Silverlight
Introduction to SilverlightIntroduction to Silverlight
Introduction to SilverlightEd Donahue
 
Calculator 1
Calculator 1Calculator 1
Calculator 1livecode
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theorynickywalters
 
Introduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneIntroduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneDave Bost
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationLee Stott
 

Similar to Windows Forms For Beginners Part - 4 (20)

Introduction
IntroductionIntroduction
Introduction
 
Windows Virtual Keyboard modification
Windows Virtual Keyboard modificationWindows Virtual Keyboard modification
Windows Virtual Keyboard modification
 
How support caller ID phone number
How support caller ID phone numberHow support caller ID phone number
How support caller ID phone number
 
3.4 events and interactivity
3.4   events and interactivity3.4   events and interactivity
3.4 events and interactivity
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
 
Gui builder
Gui builderGui builder
Gui builder
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfYOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
 
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docxMicrosoft Visual C# 2012- An introduction to object-oriented programmi.docx
Microsoft Visual C# 2012- An introduction to object-oriented programmi.docx
 
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
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting Interactivity
 
How support caller Id phone number with a modem
How support caller Id phone number with a modemHow support caller Id phone number with a modem
How support caller Id phone number with a modem
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Design
 
Botones
BotonesBotones
Botones
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...
 
follow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightfollow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlight
 
Introduction to Silverlight
Introduction to SilverlightIntroduction to Silverlight
Introduction to Silverlight
 
Calculator 1
Calculator 1Calculator 1
Calculator 1
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Introduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneIntroduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows Phone
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
 

More from Bhushan Mulmule

More from Bhushan Mulmule (12)

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Methods
MethodsMethods
Methods
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Windows Forms For Beginners Part - 4

  • 1. Demo Project: • Complex Calculator What will you learn? • Adding single event handlers • Identifying from which button handler is called. • Using flag variable to write smart Windows Forms for Beginners www.dotnetvideotutorial.com single event handlers for Multiple Buttons dentifying from which button handler is called. Using flag variable to write smart code. Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners Part 4 Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners
  • 2. www.dotnetvideotutorial.com Demo Project 1: Complex Calculator Step 1: Design UI: Instructions: • When clicked on any number button that number should get displayed on label lblDisplay. • As all numeric buttons have same functionality we will add single handler Digit_Click for click event of all numeric buttons Label: Name: lblDisplay AutoSize: False BackColor: White BorderStyle: FixedSingle Text: Blank TextAlign: MiddleRight Form: Name: frmCalculator Text: Calculator 18 Buttons: Text: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, ., C, +, -, *, /, =, OFF Name: Name accordingly for example btn1, btnPlus, btnOFF, etc 2 Group Boxes: Text: Blank
  • 3. www.dotnetvideotutorial.com • As all operator buttons have same functionality we will add single handler Operator_Click for click event of all operator buttons Step 2: Adding event handlers 1. Right click on form Click View code. 2. In class frmCalculator Declare following variables public partial class frmCalculator : Form { double no1, no2, result; string op; bool flg; ….. } 3. Insert single event handler for all numeric buttons. • First Select number 1 button (btn1) • Press Control key and then select all number buttons • Go to property window Switch to event view by clicking light sign (see image below: pointed by Event Button call out) Locate Click event Type “Digits_Click” Press enter and handler will be inserted Events Button Click Event All number buttons are selected
  • 4. www.dotnetvideotutorial.com 4. In Digits_Click() handler write following code private void Digits_Click(object sender, EventArgs e) { if (flg == true) { lblDisplay.Text = ""; flg = false; } Button btn = (Button)sender; lblDisplay.Text += btn.Text; } 5. Insert single event handler for all operator buttons • Select Plus button then press control key and select Minus, Multiplication and Division buttons. • Do not select Equal (=) button • Go to property window Events list Locate Click event and type “Operator_Click()” and press enter. code it as follow private void Operator_Click(object sender, EventArgs e) { no1 = Convert.ToInt32(lblDisplay.Text); op = ((Button)sender).Text; flg = true; } 6. Double click on equal button and insert following code private void btnEqual_Click(object sender, EventArgs e) { no2 = Convert.ToDouble(lblDisplay.Text); switch (op) { case "+": result = no1 + no2; break; case "-": result = no1 - no2; break; case "*": result = no1 * no2; break; case "/":
  • 5. www.dotnetvideotutorial.com result = no1 / no2; break; } lblDisplay.Text = result.ToString(); flg = true; } 7. Double click on point button private void btnPoint_Click(object sender, EventArgs e) { if(! lblDisplay.Text.Contains(".")) lblDisplay.Text += "."; } 8. Clear button private void btnClear_Click(object sender, EventArgs e) { no1 = 0; no2 = 0; result = 0; lblDisplay.Text = ""; } 9. OFF button private void btnOFF_Click(object sender, EventArgs e) { Application.Exit(); } 10.Execute and test. 11.Debug step by step using F11 to understand logic