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

Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 
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
 
Session 1. Bai 1 ve winform
Session 1. Bai 1 ve winformSession 1. Bai 1 ve winform
Session 1. Bai 1 ve winform
mrtom16071980
 

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
 
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
Dr-archana-dhawan-bajaj
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
Gopal Ji Singh
 

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 modification
topomax
 
How support caller ID phone number
How support caller ID phone numberHow support caller ID phone number
How support caller ID phone number
topomax
 
3.4 events and interactivity
3.4   events and interactivity3.4   events and interactivity
3.4 events and interactivity
allenbailey
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
kshyju
 
Gui builder
Gui builderGui builder
Gui builder
learnt
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting Interactivity
Gilbert 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 modem
topomax
 
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
QIRIS
 
Calculator 1
Calculator 1Calculator 1
Calculator 1
livecode
 

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

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

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