SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Demo Projects
• Validating Inputs
• Text Editor
What will you learn?
• Validating Textbox input using ‘
• Using KeyPress event to identify input character
• Using various built in methods of
• Using various dialogboxes
• Using following controls:
o ReachTextBox
o Menustrip
o Toolstrip
o Statusbar
o DialogBoxes: OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog
Windows Forms for Beginners
ox input using ‘Validating’ event
Using KeyPress event to identify input character in Textbox
Using various built in methods of ReachTextbox
Using various dialogboxes
Using following controls:
OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
Part 5
OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog
Bhushan Mulmule
bhushan.mulmule@gmail.com
www.dotnetvideotutorial.com
Windows Forms for Beginners
Demo ProjectDemo ProjectDemo ProjectDemo Project 1111:::: Validating InputValidating InputValidating InputValidating Input
Step 1: Design UI
Instructions:
• Constructor of form will get executed when form object will get created (when
form will loaded)
• Constructors are best place to initialization. So in this example we will initialize
Tag property of textbox to false in form’s constructor.
• Tag property can hold any extra information about control. (it can be normal
string)
• Validating event of textbox executes just before Leave event (lost focus) and best
place to put validation logic.
• Validation Logic 1: All the three textboxes should not be empty
o As this logic will be same for all textboxes we will add single Validating
event handler for Validating event of all three textboxes
• Validation Logic 2: Only numeric value should be allowed in Age textbox
o Value will get typed in textbox only if it is numeric
o KeyPress event fires when we press any key in textbox.
o Every key on keyboard has KeyCode.
o KeyPress event passes KeyPressEventArgs with information which key is
pressed. Using which we can only allow numeric keys
Step 2: Adding Event Handlers / Code
1. Right click form view code in constructor set some properties as follows
(insert bold code only)
public partial class frmValidatingInputs : Form
{
public frmValidatingInputs()
{
InitializeComponent();
btnOK.Enabled = false;
txtName.Tag = false;
txtCity.Tag = false;
txtAge.Tag = false;
}
. . .
}
2. Insert Validating event for all three textboxes
• Select three textboxes (using control key) Go to property window
event list Locate Validating event type “TextBoxEmpty_Validating”
and press enter code it as follow
private void TextBoxEmpty_Validating(object sender,
CancelEventArgs e)
{
TextBox txt = (TextBox)sender;
if (txt.Text.Length == 0)
{
txt.BackColor = Color.Red;
txt.Tag = false;
}
else
{
txt.BackColor = Color.White;
txt.Tag = true;
}
btnOK.Enabled = ((bool)txtName.Tag &&
(bool)txtCity.Tag && (bool)txtAge.Tag);
}
3. To insert key press event for txtAge
• Select txtAge -> Go to property window Events list Locate KeyPress
event double click on it handler will be inserted code it as follow:
private void txtAge_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled = true;
}
• Note:
o Numeric key have keychar values between 48 to 57.
o 48 for 0 …. 57 for 9
o Backspace key has keycode 8
o Above logic will cancel the event if KeyChar is not between
48 to 57 or 8
o In other words it will only allow keys with keycode 48 to 57
and 8 i.e 0 to 9 and backspace (reqred to delete)
4. Debug using F11 to understand flow
Demo Project 2Demo Project 2Demo Project 2Demo Project 2:::: Text EditorText EditorText EditorText Editor
Step 1: Design UI
Dilogboxes:
Add SaveFile, OpenFile, Font
and Color dialog boxes
Menustrip:
Add Menu as shown
Also add submenu as shown in second image below
StatusStrip:
Add 2 statuslabels and change
text and name as shown
ToolStrip:
Add Three buttons then separator and
again three buttons.
DisplayStyle: Text (for all)
And For Bold, Italic, Underline
CheckOnClick: True
Step 2: Adding event handlers
1. menuNew:
private void menuNew_Click(object sender, EventArgs e)
{
txtEditor.Visible = true;
txtEditor.Clear();
}
2. menuOpen and OpenFile function
private void menuOpen_Click(object sender, EventArgs e)
{
OpenFile();
}
private void OpenFile()
{
if (dlgOpen.ShowDialog() == DialogResult.OK)
txtEditor.LoadFile(dlgOpen.FileName);
}
3. menuSave and SaveFile function
private void menuSave_Click(object sender, EventArgs e)
{
SaveFile();
}
private void SaveFile()
{
if (dlgSave.ShowDialog() == DialogResult.OK)
txtEditor.SaveFile(dlgSave.FileName);
}
4. menuClose
private void menuClose_Click(object sender, EventArgs e)
{
txtEditor.Visible = false;
}
5. undo, redo, cut, copy paste and selectall
private void menuUndo_Click(object sender, EventArgs e)
{
txtEditor.Undo();
}
private void menuRedo_Click(object sender, EventArgs e)
{
txtEditor.Redo();
}
private void menuCut_Click(object sender, EventArgs e)
{
txtEditor.Cut();
}
private void menuCopy_Click(object sender, EventArgs e)
{
txtEditor.Copy();
}
private void menuPaste_Click(object sender, EventArgs e)
{
txtEditor.Paste();
}
private void menuSelectAll_Click(object sender, EventArgs e)
{
txtEditor.SelectAll();
}
6. menuFont
private void menuFont_Click(object sender, EventArgs e)
{
if(dlgFont.ShowDialog() == DialogResult.OK)
txtEditor.SelectionFont = dlgFont.Font;
}
7. ForeColor and BackColor
private void menuForeColor_Click(object sender, EventArgs e)
{
if (dlgColor.ShowDialog() == DialogResult.OK)
txtEditor.SelectionColor = dlgColor.Color;
}
private void menBackColor_Click(object sender, EventArgs e)
{
if (dlgColor.ShowDialog() == DialogResult.OK)
txtEditor.BackColor = dlgColor.Color;
}
8. menuExit
private void menuExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
9. toolNew
private void toolNew_Click(object sender, EventArgs e)
{
txtEditor.Visible = true;
txtEditor.Clear();
}
10.toolOpen
private void toolOpen_Click(object sender, EventArgs e)
{
OpenFile();
}
11.toolSave
private void toolSave_Click(object sender, EventArgs e)
{
SaveFile();
}
12.toolBold
private void toolBold_Click(object sender, EventArgs e)
{
Font Currentfnt = txtEditor.SelectionFont;
if(toolBold.Checked)
txtEditor.SelectionFont =
new Font (Currentfnt,Currentfnt.Style |
FontStyle.Bold);
else
txtEditor.SelectionFont =
new Font(Currentfnt, Currentfnt.Style &
~FontStyle.Bold);
}
13.toolItalic
private void toolItalic_Click(object sender, EventArgs e)
{
Font Currentfnt = txtEditor.SelectionFont;
if (toolItalic.Checked)
txtEditor.SelectionFont =
new Font(Currentfnt, Currentfnt.Style |
FontStyle.Italic);
else
txtEditor.SelectionFont =
new Font(Currentfnt, Currentfnt.Style &
~FontStyle.Italic);
}
14.toolUnderline
private void toolUnderline_Click(object sender, EventArgs e)
{
Font Currentfnt = txtEditor.SelectionFont;
if (toolUnderline.Checked)
txtEditor.SelectionFont =
new Font(Currentfnt, Currentfnt.Style |
FontStyle.Underline);
else
txtEditor.SelectionFont =
new Font(Currentfnt, Currentfnt.Style &
~FontStyle.Underline);
}
15.MyTextditor_TextChange()
private void MyEditor_TextChanged(object sender, EventArgs e)
{
statusLines.Text = txtEditor.Lines.Count().ToString() + "
Lines";
statusChars.Text = txtEditor.TextLength.ToString() + "
Characters";
}

Weitere ähnliche Inhalte

Was ist angesagt? (20)

06 win forms
06 win forms06 win forms
06 win forms
 
Vs c# lecture1
Vs c# lecture1Vs c# lecture1
Vs c# lecture1
 
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&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.154.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
 
Controls events
Controls eventsControls events
Controls events
 
Vs c# lecture3
Vs c# lecture3Vs c# lecture3
Vs c# lecture3
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Vs c# lecture2
Vs c# lecture2Vs c# lecture2
Vs c# lecture2
 
Spf chapter10 events
Spf chapter10 eventsSpf chapter10 events
Spf chapter10 events
 
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
 
Vs c# lecture5
Vs c# lecture5Vs c# lecture5
Vs c# lecture5
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Vs c# lecture4
Vs c# lecture4Vs c# lecture4
Vs c# lecture4
 
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
 
Session 1. Bai 1 ve winform
Session 1. Bai 1 ve winformSession 1. Bai 1 ve winform
Session 1. Bai 1 ve winform
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 

Andere mochten auch

Andere mochten auch (6)

Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
Ch2 ar
Ch2 arCh2 ar
Ch2 ar
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
 
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
 

Ähnlich wie Windows Forms Demo Projects

Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12HUST
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Managementpritamkumar
 
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
 
Android basics – dialogs and floating activities
Android basics – dialogs and floating activitiesAndroid basics – dialogs and floating activities
Android basics – dialogs and floating activitiesinfo_zybotech
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshopdhi her
 
I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxcwayne3
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxRAHUL126667
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls objectallenbailey
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introductionbloodyedge03
 
Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfArielManzano3
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed contentYogesh Kumar
 

Ähnlich wie Windows Forms Demo Projects (20)

Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Management
 
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
 
Android basics – dialogs and floating activities
Android basics – dialogs and floating activitiesAndroid basics – dialogs and floating activities
Android basics – dialogs and floating activities
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
WPF Controls
WPF ControlsWPF Controls
WPF Controls
 
12 gui concepts 1
12 gui concepts 112 gui concepts 1
12 gui concepts 1
 
4.C#
4.C#4.C#
4.C#
 
I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docx
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
Android session 3
Android session 3Android session 3
Android session 3
 
final project for C#
final project for C#final project for C#
final project for C#
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls object
 
Gui builder
Gui builderGui builder
Gui builder
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
 
Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdf
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed content
 

Mehr von Bhushan Mulmule

Mehr von 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
 

Kürzlich hochgeladen

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Kürzlich hochgeladen (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Windows Forms Demo Projects

  • 1. Demo Projects • Validating Inputs • Text Editor What will you learn? • Validating Textbox input using ‘ • Using KeyPress event to identify input character • Using various built in methods of • Using various dialogboxes • Using following controls: o ReachTextBox o Menustrip o Toolstrip o Statusbar o DialogBoxes: OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog Windows Forms for Beginners ox input using ‘Validating’ event Using KeyPress event to identify input character in Textbox Using various built in methods of ReachTextbox Using various dialogboxes Using following controls: OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners Part 5 OpenFileDialog,SaveFileDialog, FontDialog, ColorDialog Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners
  • 2. Demo ProjectDemo ProjectDemo ProjectDemo Project 1111:::: Validating InputValidating InputValidating InputValidating Input Step 1: Design UI Instructions: • Constructor of form will get executed when form object will get created (when form will loaded) • Constructors are best place to initialization. So in this example we will initialize Tag property of textbox to false in form’s constructor. • Tag property can hold any extra information about control. (it can be normal string) • Validating event of textbox executes just before Leave event (lost focus) and best place to put validation logic. • Validation Logic 1: All the three textboxes should not be empty o As this logic will be same for all textboxes we will add single Validating event handler for Validating event of all three textboxes • Validation Logic 2: Only numeric value should be allowed in Age textbox o Value will get typed in textbox only if it is numeric o KeyPress event fires when we press any key in textbox. o Every key on keyboard has KeyCode. o KeyPress event passes KeyPressEventArgs with information which key is pressed. Using which we can only allow numeric keys
  • 3. Step 2: Adding Event Handlers / Code 1. Right click form view code in constructor set some properties as follows (insert bold code only) public partial class frmValidatingInputs : Form { public frmValidatingInputs() { InitializeComponent(); btnOK.Enabled = false; txtName.Tag = false; txtCity.Tag = false; txtAge.Tag = false; } . . . } 2. Insert Validating event for all three textboxes • Select three textboxes (using control key) Go to property window event list Locate Validating event type “TextBoxEmpty_Validating” and press enter code it as follow private void TextBoxEmpty_Validating(object sender, CancelEventArgs e) { TextBox txt = (TextBox)sender; if (txt.Text.Length == 0) { txt.BackColor = Color.Red; txt.Tag = false; } else { txt.BackColor = Color.White; txt.Tag = true; } btnOK.Enabled = ((bool)txtName.Tag && (bool)txtCity.Tag && (bool)txtAge.Tag); }
  • 4. 3. To insert key press event for txtAge • Select txtAge -> Go to property window Events list Locate KeyPress event double click on it handler will be inserted code it as follow: private void txtAge_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8) e.Handled = true; } • Note: o Numeric key have keychar values between 48 to 57. o 48 for 0 …. 57 for 9 o Backspace key has keycode 8 o Above logic will cancel the event if KeyChar is not between 48 to 57 or 8 o In other words it will only allow keys with keycode 48 to 57 and 8 i.e 0 to 9 and backspace (reqred to delete) 4. Debug using F11 to understand flow Demo Project 2Demo Project 2Demo Project 2Demo Project 2:::: Text EditorText EditorText EditorText Editor Step 1: Design UI
  • 5. Dilogboxes: Add SaveFile, OpenFile, Font and Color dialog boxes Menustrip: Add Menu as shown Also add submenu as shown in second image below StatusStrip: Add 2 statuslabels and change text and name as shown ToolStrip: Add Three buttons then separator and again three buttons. DisplayStyle: Text (for all) And For Bold, Italic, Underline CheckOnClick: True
  • 6. Step 2: Adding event handlers 1. menuNew: private void menuNew_Click(object sender, EventArgs e) { txtEditor.Visible = true; txtEditor.Clear(); } 2. menuOpen and OpenFile function private void menuOpen_Click(object sender, EventArgs e) { OpenFile(); } private void OpenFile() { if (dlgOpen.ShowDialog() == DialogResult.OK) txtEditor.LoadFile(dlgOpen.FileName); } 3. menuSave and SaveFile function private void menuSave_Click(object sender, EventArgs e) { SaveFile(); } private void SaveFile() { if (dlgSave.ShowDialog() == DialogResult.OK) txtEditor.SaveFile(dlgSave.FileName); } 4. menuClose private void menuClose_Click(object sender, EventArgs e) { txtEditor.Visible = false; }
  • 7. 5. undo, redo, cut, copy paste and selectall private void menuUndo_Click(object sender, EventArgs e) { txtEditor.Undo(); } private void menuRedo_Click(object sender, EventArgs e) { txtEditor.Redo(); } private void menuCut_Click(object sender, EventArgs e) { txtEditor.Cut(); } private void menuCopy_Click(object sender, EventArgs e) { txtEditor.Copy(); } private void menuPaste_Click(object sender, EventArgs e) { txtEditor.Paste(); } private void menuSelectAll_Click(object sender, EventArgs e) { txtEditor.SelectAll(); } 6. menuFont private void menuFont_Click(object sender, EventArgs e) { if(dlgFont.ShowDialog() == DialogResult.OK) txtEditor.SelectionFont = dlgFont.Font; } 7. ForeColor and BackColor private void menuForeColor_Click(object sender, EventArgs e) { if (dlgColor.ShowDialog() == DialogResult.OK) txtEditor.SelectionColor = dlgColor.Color; }
  • 8. private void menBackColor_Click(object sender, EventArgs e) { if (dlgColor.ShowDialog() == DialogResult.OK) txtEditor.BackColor = dlgColor.Color; } 8. menuExit private void menuExit_Click(object sender, EventArgs e) { Application.Exit(); } 9. toolNew private void toolNew_Click(object sender, EventArgs e) { txtEditor.Visible = true; txtEditor.Clear(); } 10.toolOpen private void toolOpen_Click(object sender, EventArgs e) { OpenFile(); } 11.toolSave private void toolSave_Click(object sender, EventArgs e) { SaveFile(); } 12.toolBold private void toolBold_Click(object sender, EventArgs e) { Font Currentfnt = txtEditor.SelectionFont; if(toolBold.Checked) txtEditor.SelectionFont = new Font (Currentfnt,Currentfnt.Style | FontStyle.Bold); else txtEditor.SelectionFont =
  • 9. new Font(Currentfnt, Currentfnt.Style & ~FontStyle.Bold); } 13.toolItalic private void toolItalic_Click(object sender, EventArgs e) { Font Currentfnt = txtEditor.SelectionFont; if (toolItalic.Checked) txtEditor.SelectionFont = new Font(Currentfnt, Currentfnt.Style | FontStyle.Italic); else txtEditor.SelectionFont = new Font(Currentfnt, Currentfnt.Style & ~FontStyle.Italic); } 14.toolUnderline private void toolUnderline_Click(object sender, EventArgs e) { Font Currentfnt = txtEditor.SelectionFont; if (toolUnderline.Checked) txtEditor.SelectionFont = new Font(Currentfnt, Currentfnt.Style | FontStyle.Underline); else txtEditor.SelectionFont = new Font(Currentfnt, Currentfnt.Style & ~FontStyle.Underline); } 15.MyTextditor_TextChange() private void MyEditor_TextChanged(object sender, EventArgs e) { statusLines.Text = txtEditor.Lines.Count().ToString() + " Lines"; statusChars.Text = txtEditor.TextLength.ToString() + " Characters"; }