SlideShare a Scribd company logo
Working with Form
Chapter II
Message Boxes
• A message box is a special dialog box used to display a piece of information to user.
– MessageBox class
– EX:
MessageBox.Show("Hello, how are you?","My SMS");
MessageBox.Show("Welcome to the Wonderful World of Visual C#","Visual C#
Tutorials", MessageBoxButtons.OKCancel);
MessageBox.Show("Your order appears to be correct" +
"nAre you ready to provide your credit card information?",
"Customer Order Processing",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Information);
EX:
MessageBox.Show("Your order appears to be correct" +
"nAre you ready to provide your credit card information?",
"Customer Order Processing",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
NOTE:Button1 , Button2 , Button3
private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') || e.KeyChar==' ')
{
e.Handled =true;
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9'))
{
e.Handled = true;
}
}
Note: || (e.KeyChar == (char)Keys.Back)
1. Button
2. OpenFileDialog Control
3. Picture Box
this.WindowState = FormWindowState.Minimized;
this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Maximized;
EX:
foreach (Control c in this.Controls)
{
TextBox t = c as TextBox;
ComboBox cbo = c as ComboBox;
if (t != null)
{
t.Text = " ";
}
else if (cbo != null)
{
cbo.Text = " ";
}
}
Radiobutton and CheckBox
ListBox
Creating Timers
Creating Tabbed Dialog Boxes
Creating List View
1. Adding Menu Items
2. Creating Checked Menu Items
3. Assigning Shortcut Keys
4. Using the Toolbar Control
Creating MDI Forms
All the projects you've created so far have been single-document interface (SDI) projects. In SDI
programs, every form in the application is a peer of all other forms; no intrinsic hierarchy exists
between forms. C# also lets you create multiple-document interface (MDI) programs. A MDI
program contains one parent window (also called a container) and one or more child windows.
A classic example of a MDI program is Microsoft Word 95 (200 behaves slightly different,
depending on how it's set up).
this.Hide();
Form2 frm2 = new Form2();
frm2.Show();

More Related Content

Viewers also liked

android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management System
Tanner Jessel
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feed
Tanuja Talekar
 
how to setup Google analytics tracking code for website
how to setup  Google analytics tracking code for websitehow to setup  Google analytics tracking code for website
how to setup Google analytics tracking code for website
OM Maurya
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
BlackRabbitCoder
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
Jm Ramos
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon
 

Viewers also liked (11)

Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdi
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management System
 
SQLite - Overview
SQLite - OverviewSQLite - Overview
SQLite - Overview
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feed
 
how to setup Google analytics tracking code for website
how to setup  Google analytics tracking code for websitehow to setup  Google analytics tracking code for website
how to setup Google analytics tracking code for website
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Programming in c#
Programming in c#Programming in c#
Programming in c#
 

Similar to Chapter ii c#(building a user interface)

PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
Ali Mattash
 
Inventory management
Inventory managementInventory management
Inventory managementRajeev Sharan
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorialjayguyab
 
06 win forms
06 win forms06 win forms
06 win forms
mrjw
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshopdhi her
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Winisisx
WinisisxWinisisx
Winisisx
Victor789
 
You have been engaged to develop a special calculator program. T.docx
You have been engaged to develop a special calculator program. T.docxYou have been engaged to develop a special calculator program. T.docx
You have been engaged to develop a special calculator program. T.docx
briancrawford30935
 
Visual programming is a type of programming
Visual programming is a type of programmingVisual programming is a type of programming
Visual programming is a type of programming
sanaiftikhar23
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorialdhi her
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
Mahmoud Ouf
 
Functions 1
Functions 1Functions 1
Functions 1Spy Seat
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
Mahmoud Ouf
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
Andi Simanjuntak
 

Similar to Chapter ii c#(building a user interface) (20)

PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
Inventory management
Inventory managementInventory management
Inventory management
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
06 win forms
06 win forms06 win forms
06 win forms
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
4.C#
4.C#4.C#
4.C#
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Winisisx
WinisisxWinisisx
Winisisx
 
You have been engaged to develop a special calculator program. T.docx
You have been engaged to develop a special calculator program. T.docxYou have been engaged to develop a special calculator program. T.docx
You have been engaged to develop a special calculator program. T.docx
 
Visual programming is a type of programming
Visual programming is a type of programmingVisual programming is a type of programming
Visual programming is a type of programming
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Functions 1
Functions 1Functions 1
Functions 1
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 

More from Chhom Karath

set1.pdf
set1.pdfset1.pdf
set1.pdf
Chhom Karath
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
Chhom Karath
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
Chhom Karath
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
Chhom Karath
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
Chhom Karath
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
Chhom Karath
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
Chhom Karath
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
Chhom Karath
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
Chhom Karath
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
Chhom Karath
 
Bracket size
Bracket sizeBracket size
Bracket size
Chhom Karath
 
Couple
CoupleCouple
Couple
Chhom Karath
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
Chhom Karath
 
Game1
Game1Game1
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
Chhom Karath
 
Opus loop
Opus loopOpus loop
Opus loop
Chhom Karath
 
V bend
V bendV bend
V bend
Chhom Karath
 
Closing loop
Closing loopClosing loop
Closing loop
Chhom Karath
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
Chhom Karath
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
Chhom Karath
 

More from Chhom Karath (20)

set1.pdf
set1.pdfset1.pdf
set1.pdf
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
 
Bracket size
Bracket sizeBracket size
Bracket size
 
Couple
CoupleCouple
Couple
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
 
Game1
Game1Game1
Game1
 
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
 
Opus loop
Opus loopOpus loop
Opus loop
 
V bend
V bendV bend
V bend
 
Closing loop
Closing loopClosing loop
Closing loop
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 

Chapter ii c#(building a user interface)

  • 2. Message Boxes • A message box is a special dialog box used to display a piece of information to user. – MessageBox class – EX: MessageBox.Show("Hello, how are you?","My SMS"); MessageBox.Show("Welcome to the Wonderful World of Visual C#","Visual C# Tutorials", MessageBoxButtons.OKCancel); MessageBox.Show("Your order appears to be correct" + "nAre you ready to provide your credit card information?", "Customer Order Processing", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
  • 3. EX: MessageBox.Show("Your order appears to be correct" + "nAre you ready to provide your credit card information?", "Customer Order Processing", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); NOTE:Button1 , Button2 , Button3
  • 4. private void txtNumber_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') || e.KeyChar==' ') { e.Handled =true; } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0' && e.KeyChar <= '9')) { e.Handled = true; } } Note: || (e.KeyChar == (char)Keys.Back)
  • 5. 1. Button 2. OpenFileDialog Control 3. Picture Box
  • 6. this.WindowState = FormWindowState.Minimized; this.WindowState = FormWindowState.Normal; this.WindowState = FormWindowState.Maximized; EX: foreach (Control c in this.Controls) { TextBox t = c as TextBox; ComboBox cbo = c as ComboBox; if (t != null) { t.Text = " "; } else if (cbo != null) { cbo.Text = " "; } }
  • 12. 1. Adding Menu Items 2. Creating Checked Menu Items 3. Assigning Shortcut Keys 4. Using the Toolbar Control
  • 13. Creating MDI Forms All the projects you've created so far have been single-document interface (SDI) projects. In SDI programs, every form in the application is a peer of all other forms; no intrinsic hierarchy exists between forms. C# also lets you create multiple-document interface (MDI) programs. A MDI program contains one parent window (also called a container) and one or more child windows. A classic example of a MDI program is Microsoft Word 95 (200 behaves slightly different, depending on how it's set up).
  • 14. this.Hide(); Form2 frm2 = new Form2(); frm2.Show();

Editor's Notes

  1. if (MessageBox.Show("Would you like to do X?", "MessageBoxsample", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); }
  2. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Text = DateTime.Now.ToString(); this.rSum.Checked = true; } private void rSum_CheckedChanged(object sender, EventArgs e) { this.lbOp.Text = "+"; this.btOP.Text = "+"; } private void rMinus_CheckedChanged(object sender, EventArgs e) { this.lbOp.Text = "-"; this.btOP.Text = "-"; } private void rMult_CheckedChanged(object sender, EventArgs e) { this.lbOp.Text = "*"; this.btOP.Text = "*"; } private void rDiv_CheckedChanged(object sender, EventArgs e) { this.lbOp.Text = "/"; this.btOP.Text = "/"; } private void btOP_Click(object sender, EventArgs e) { Random rnd = new Random(); this.lbV1.Text = (rnd.Next(100)).ToString(); this.lbV2.Text = (rnd.Next(100)).ToString(); switch (this.lbOp.Text) { case "+": lbResult.Text = (float.Parse(lbV1.Text) + float.Parse(lbV2.Text)).ToString(); break; case "-": lbResult.Text = (float.Parse(lbV1.Text) - float.Parse(lbV2.Text)).ToString(); break; case "*": lbResult.Text = (float.Parse(lbV1.Text) * float.Parse(lbV2.Text)).ToString(); break; case "/": lbResult.Text = (float.Parse(lbV1.Text) / float.Parse(lbV2.Text)).ToString(); break; } } private void button2_Click(object sender, EventArgs e) { this.Close(); } } }
  3. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void cmdOK_Click(object sender, EventArgs e) { string output; output="ID: " + txtID.Text + "\r\n"; output+= "Name: " + txtName.Text + "\r\n"; output+="Gender: " + txtGender.Text + "\r\n"; output+="DOB:" + txtDOB.Text + "\r\n"; output += "Address:" + txtGender.Text + "\r\n____________________________________\r\n"; txtOUTPUT.Text =txtOUTPUT.Text + output; } private void cmdHELP_Click(object sender, EventArgs e) { string output; output = "ID= Your ID\r\n"; output +="Name = Your name\r\n"; output +="Sex = Your sex\r\n"; output += "Address = Your address\r\n"; output += "DOB = Your date of birth 'dd/mm/yyyy'\r\n"; // Insert the new text. this.txtOUTPUT.Text = output; } } } //_____________________________________ private Boolean isDate(String st) { Boolean b = true; try { DateTime dt = DateTime.Parse(st); } catch { return false; } return true; } private void textBox1_Leave(object sender, EventArgs e) { if (isDate(this.textBox1.Text)==false) { MessageBox.Show("Please, enter only date!"); this.textBox1.Focus(); } }
  4. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.oFD.Filter = "Windows Bitmaps|*.BMP|JPEG Files|*.JPG"; } private void btSelect_Click(object sender, EventArgs e) { oFD.InitialDirectory = @"C:\"; oFD.Title = "Select a File"; this.oFD.FileName = ""; if (this.oFD.ShowDialog() == DialogResult.OK) { this.pBox.Image = Image.FromFile(oFD.FileName); this.Text = String.Concat("Picture Viewer (" + oFD.FileName + ")"); this.cboPath.Items.Add(oFD.FileName); } } private void btQuit_Click(object sender, EventArgs e) { this.Close(); } private void cboPath_SelectedIndexChanged(object sender, EventArgs e) { this.pBox.Image = Image.FromFile(cboPath.Text); } } }
  5. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btEnlarge_Click(object sender, EventArgs e) { this.Width = this.Width + 20; this.Height = this.Height + 20; } private void btShrink_Click(object sender, EventArgs e) { this.Width = this.Width - 20; this.Height = this.Height - 20; } private void btObject_Click(object sender, EventArgs e) { for (int intIndex = 0; intIndex < this.Controls.Count;intIndex++) { MessageBox.Show("Control # " + intIndex.ToString() +" has the name " + this.Controls[intIndex].Name); } } } }
  6. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _5 { public partial class Form1 : Form { public static string opt; public static string u1; public static string u2; public Form1() { InitializeComponent(); } private static double operate(string v1, string v2, string opt) { double result=0; switch (opt) { case "+": result = double.Parse(v1) + double.Parse(v2); break; case "-": result = double.Parse(v1) - double.Parse(v2); break; case "*": result = double.Parse(v1) * double.Parse(v2); break; case "/": result = double.Parse(v1) - double.Parse(v2); break; case "Min": result = (double.Parse(v1)> double.Parse(v2))?double.Parse(v2):double.Parse(v1); break; case "Max": result = (double.Parse(v1)> double.Parse(v2))?double.Parse(v1):double.Parse(v2); break; } return result; } private void rBSum_CheckedChanged(object sender, EventArgs e) { if (this.rBSum.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "+"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void rBMinus_CheckedChanged(object sender, EventArgs e) { if (this.rBMinus.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "-"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void rbMult_CheckedChanged(object sender, EventArgs e) { if (this.rbMult.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "*"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void rBDiv_CheckedChanged(object sender, EventArgs e) { if (this.rBDiv.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "/"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void rbMin_CheckedChanged(object sender, EventArgs e) { if (this.rbMin.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "Min"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void rBMax_CheckedChanged(object sender, EventArgs e) { if (this.rBMax.Checked) { if (this.txtVal1.Text == "") { MessageBox.Show("សូមវាតតំលៃទី១"); this.txtVal1.Focus(); } else if (this.txtVal2.Text == "") { MessageBox.Show("សូមវាតតំលៃទី២"); this.txtVal2.Focus(); } else { opt = "Max"; this.txtResult.Text = (operate(this.txtVal1.Text, this.txtVal2.Text, opt)).ToString(); } } } private void chClear_CheckedChanged(object sender, EventArgs e) { if (this.chClear.Checked) { u1 = this.txtVal1.Text; u2 = this.txtVal2.Text; this.txtVal1.Text = ""; this.txtVal2.Text = ""; this.txtResult.Text = ""; } } private void chUndo_CheckedChanged(object sender, EventArgs e) { if (chUndo.Checked) { this.txtVal1.Text = u1; this.txtVal2.Text = u2; } } } }
  7. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btSearch_Click(object sender, EventArgs e) { Boolean b=false; for (int i = 0; i < lstProduct.Items.Count; i++) { if (lstProduct.Items[i].ToString() == (txtProID.Text + "\t" + txtProName.Text + "\t" + txtQty.Text + "\t" + txtUnitPrice.Text + "\t" + double.Parse(txtQty.Text) * double.Parse(txtUnitPrice.Text))) { lstProduct.Focus(); lstProduct.SelectedIndex=i ; b = true; return; } } if (b == false) { MessageBox.Show("រកមិនឃើញទេ!"); } } private void btInsert_Click(object sender, EventArgs e) { this.lstProduct.Items.Add(txtProID.Text + "\t" + txtProName.Text + "\t" + txtQty.Text + "\t" + txtUnitPrice.Text + "\t" + double.Parse(txtQty.Text)*double.Parse(txtUnitPrice.Text)); } private void btDelete_Click(object sender, EventArgs e) { if (this.lstProduct.SelectedIndex!=-1) { //this.lstProduct.Items.Remove(this.lstProduct.Text); this.lstProduct.Items.RemoveAt(this.lstProduct.SelectedIndex); } } private static string IdProduct() { return ""; // for(int i=0;i< } private void btNew_Click(object sender, EventArgs e) { txtProID.Text = ""; txtProName.Text = ""; txtQty.Text = ""; txtUnitPrice.Text = ""; } private void Form1_Load(object sender, EventArgs e) { this.lstProduct.Sorted = true; } } }
  8. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _7 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void TM_Tick(object sender, EventArgs e) { this.lbDay.BackColor = Color.AliceBlue; DateTime objToday = DateTime.Now; lbDay.Text = (objToday.DayOfWeek).ToString(); lbTime.Text = "Time: " + objToday.ToLongTimeString(); lbMonth.Text ="Month: " + (objToday.Month).ToString(); lbD.Text = "Day: " + (objToday.Day).ToString(); lbYear.Text = (objToday.Year).ToString(); } } }
  9. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _8 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btResult1_Click(object sender, EventArgs e) { int i=0; int s=0; while(i < 10) { i = i + 1; s = s + i; } this.txtResult1.Text = s.ToString(); } private void btResult2_Click(object sender, EventArgs e) { int i = 1; int s = 0; while (i < 10) { s = s + i; i = i + 2; } this.txtResult2.Text = s.ToString(); } private void btResult3_Click(object sender, EventArgs e) { int i = 2; int s = 0; while (i <= 10) { s = s + i; i = i + 2; } this.txtResult3.Text = s.ToString(); } private void tabControl1_MouseClick(object sender, MouseEventArgs e) { int i = 0; double rndNum = 0; Random rnd = new Random(); do { rndNum = rnd.Next(10) + 1; cboValue.Items.Add(Math.Round(rndNum)); i = i + 1; } while (i < 10); } private void btMin_Click(object sender, EventArgs e) { int i=0; int min=int.Parse(cboValue.Items[0].ToString()); do { if(min>int.Parse(cboValue.Items[i].ToString())) { min=int.Parse(cboValue.Items[i].ToString()); } i=i+1; }while(i<cboValue.Items.Count); txtMin.Text=min.ToString(); } private void btMax_Click(object sender, EventArgs e) { int i = 0; int max = int.Parse(cboValue.Items[0].ToString()); do { if (max < int.Parse(cboValue.Items[i].ToString())) { max = int.Parse(cboValue.Items[i].ToString()); } i = i + 1; } while (i < cboValue.Items.Count); txtMax.Text = max.ToString(); } private void btRnd_Click(object sender, EventArgs e) { cboValue.Items.Clear(); int i = 0; double rndNum = 0; Random rnd = new Random(); do { rndNum = rnd.Next(10) + 1; cboValue.Items.Add(Math.Round(rndNum)); i = i + 1; } while (i < 10); } } }
  10. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _10 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.cboGender.Items.Add("Male"); this.cboGender.Items.Add("Female"); this.cboGender.SelectedIndex = 0; lvwCustomer.View = View.Details; lvwCustomer.Columns.Add("CustID", 120, HorizontalAlignment.Left); ColumnHeader colCustName = new ColumnHeader(); colCustName.Text = "CustName"; colCustName.Width = 120; colCustName.TextAlign = HorizontalAlignment.Right; ColumnHeader colGender = new ColumnHeader(); colGender.Text = "Gender"; colGender.Width = 80; colGender.TextAlign = HorizontalAlignment.Right; ColumnHeader colDOB = new ColumnHeader(); colDOB.Text = "Date of birth"; colDOB.Width = 120; colDOB.TextAlign = HorizontalAlignment.Right; ColumnHeader colAddress = new ColumnHeader(); colAddress.Text = "Address"; colAddress.Width = 200; colAddress.TextAlign = HorizontalAlignment.Right; ColumnHeader colPhoto = new ColumnHeader(); colPhoto.Text = "Path"; colPhoto.Width = 200; colPhoto.TextAlign = HorizontalAlignment.Left; ColumnHeader[] cols = {colCustName , colGender,colDOB,colAddress,colPhoto}; lvwCustomer.Columns.AddRange(cols); } private void btClear_Click(object sender, EventArgs e) { this.txtCustID.Text = ""; this.txtCustName.Text = ""; this.txtAddress.Text = ""; this.txtDOB.Text = ""; } private static string path; private void pictureBox1_DoubleClick(object sender, EventArgs e) { oFD.InitialDirectory = @"C:\"; oFD.Title = "Select a File"; this.oFD.FileName = ""; if (this.oFD.ShowDialog() == DialogResult.OK) { this.pB.Image = Image.FromFile(oFD.FileName); path = oFD.FileName; } } private void btInsert_Click(object sender, EventArgs e) { ListViewItem lvicust = lvwCustomer.Items.Add(this.txtCustID.Text); lvicust.SubItems.Add(this.txtCustName.Text); lvicust.SubItems.Add(this.cboGender.Text); lvicust.SubItems.Add(this.txtDOB.Text); lvicust.SubItems.Add(this.txtAddress.Text); lvicust.SubItems.Add(path); } private void btDelete_Click(object sender, EventArgs e) { int i; Boolean b=false; for (i = lvwCustomer.Items.Count-1; i >= 0; i--) { if (lvwCustomer.Items[i].Selected == true) { lvwCustomer.Items.RemoveAt(i); b = true; } } if (b == false) { MessageBox.Show("Cannot delete, no items te"); } } private void lvwCustomer_Click(object sender, EventArgs e) { int i; for (i = lvwCustomer.Items.Count - 1; i >= 0; i--) { if (lvwCustomer.Items[i].Selected == true) { txtCustID.Text = lvwCustomer.Items[i].Text; txtCustName.Text = lvwCustomer.Items[i].SubItems[1].Text; cboGender.Text = lvwCustomer.Items[i].SubItems[2].Text; txtDOB.Text = lvwCustomer.Items[i].SubItems[3].Text; txtAddress.Text = lvwCustomer.Items[i].SubItems[4].Text; this.pB.Image = Image.FromFile(lvwCustomer.Items[i].SubItems[5].Text); break; } } } private void lvwCustomer_SelectedIndexChanged(object sender, EventArgs e) { } private void pB_Click(object sender, EventArgs e) { } private void btUpdate_Click(object sender, EventArgs e) { int i; Boolean b = false; for (i = lvwCustomer.Items.Count - 1; i >= 0; i--) { if (lvwCustomer.Items[i].Selected == true) { lvwCustomer.Items[i].SubItems[1].Text = this.txtCustName.Text; lvwCustomer.Items[i].SubItems[2].Text = this.cboGender.Text; lvwCustomer.Items[i].SubItems[3].Text = this.txtDOB.Text; lvwCustomer.Items[i].SubItems[4].Text = this.txtAddress.Text; lvwCustomer.Items[i].SubItems[5].Text = path; b = true; } } if (b == false) { MessageBox.Show("Cannot Update te"); } } private void btSearch_Click(object sender, EventArgs e) { int i; Boolean b = false; for (i = lvwCustomer.Items.Count - 1; i >= 0; i--) { if (lvwCustomer.Items[i].Text == this.txtCustID.Text) { this.txtCustName.Text = lvwCustomer.Items[i].SubItems[1].Text; this.cboGender.Text = lvwCustomer.Items[i].SubItems[2].Text; this.txtDOB.Text=lvwCustomer.Items[i].SubItems[3].Text; this.txtAddress.Text=lvwCustomer.Items[i].SubItems[4].Text; this.pB.Image =Image.FromFile(lvwCustomer.Items[i].SubItems[5].Text); b = true; } } if (b == false) { MessageBox.Show("Cannot Update te"); } } } }
  11. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _11 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if (!closeToolStripMenuItem.Checked) { if (MessageBox.Show("Do you really wish to exit?","QuitVerification",MessageBoxButtons.YesNo) ==DialogResult.No) return; } this.Close(); } private void Form1_Load(object sender, EventArgs e) { closeToolStripMenuItem.Checked = (!closeToolStripMenuItem.Checked); } } }
  12. private void form1ToolStripMenuItem_Click(object sender, EventArgs e) { fchChild1 objChild = new fchChild1(); objChild.MdiParent = this; objChild.Show(); } private void form2ToolStripMenuItem_Click(object sender, EventArgs e) { fchChild2 objChild = new fchChild2(); objChild.MdiParent = this; objChild.Show(); }