SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
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";
}

Contenu connexe

Tendances (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
 

En vedette

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de Bhushan Mulmule

Plus de 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
 

Dernier

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 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"; }