SlideShare a Scribd company logo
1 of 14
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 SystemTanner Jessel
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feedTanuja 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 websiteOM 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 notesWE-IT TUTORIALS
 
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# IntroductionSiraj 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 RAMALINGAMSaraswathiRamalingam
 
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 formsmrjw
 
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
 
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.docxbriancrawford30935
 
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 programmingsanaiftikhar23
 
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 5Bhushan Mulmule
 
Functions 1
Functions 1Functions 1
Functions 1Spy Seat
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 

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

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

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

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(); }