Windows Forms For Beginners Part - 1

  • 367 views
Uploaded on

Simple example for who are very new to .NET Windows Forms. (Not for who know some basics)

Simple example for who are very new to .NET Windows Forms. (Not for who know some basics)

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
367
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
16
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Demo Projects • Simple Calculator • Student Progress Report What will you learn? • Designing simple user • Changing properties of controls • Writing event handler for button • Using following controls: o Labels o Textboxes o Buttons o Group-box Windows Forms for Beginners Student Progress Report ser interface Changing properties of controls Writing event handler for button’s click event controls: Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners Part 1 Bhushan Mulmule bhushan.mulmule@gmail.com www.dotnetvideotutorial.com Windows Forms for Beginners
  • 2. Project 1: Basic Calculator • Create New Windows Form Application • Step 1: Design User Interface • Step 2: Change Properties of labels, textboxes and buttons • Step 3: Write Code for buttons Step 1: Design UI as follow: Labels Arrange No1, No2 and Result labels to align right walls Textboxes User should not able to type in result textbox. In next example to show output we will use labels Buttons
  • 3. www.dotnetvideotutorial.com Step 2: Set properties of controls as follow: Control Name Text Readonly Form frmBasicCalcii Basic Calculator Labels No need to change Names of labels at left hand side Basic Calculator Number 1: Number 2: Result: TextBoxes txtNo1 txtNo2 txtResult True Buttons btnPlus + btnMinus - btnMul * btnDiv / btnReset Reset btnExit Exit Step 3: Add event handlers for buttons 1. Double click on Plus button and code it as follow: private void btnPlus_Click(object sender, EventArgs e) { int no1, no2, result; no1 = Convert.ToInt32(txtNo1.Text); no2 = Convert.ToInt32(txtNo2.Text); result = no1 + no2; txtResult.Text = result.ToString(); } Note: Write similar code for minus, multiplication and division.
  • 4. www.dotnetvideotutorial.com 2. Double click Reset button and write code as follow: private void btnClear_Click(object sender, EventArgs e) { //txtNo1.Text = ""; txtNo1.Clear(); txtNo2.Clear(); txtResult.Clear(); txtNo1.Focus(); } 3. Double click Exit button and write code as follow: private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } 4. Application is ready execute and test. Project 2: Student Progress Report Step 1: Design UI And Change Properties as shown in callouts (Please use common sense☺☺☺☺) • Change Title Label Font size property to make it large • No need to change Name property of labels at left-hand side as not used in code • Change only Text property of labels as shown in image • Change names for all textboxes as specified in callouts respectively • Change names for Right hand side output labels for Total, Percentage, Division and Total. • Do not change names of left hand side total, percentage, division and total labels • To change looks of right hand side output labels change AutoSize: False, BackColor: White, BorderStyle: FixedSingle, Text: Blank • Change only Text property of Group-box.
  • 5. 2 Textboxes Name: txtRollNo, txtName 5 TextBoxes: Name: txtEng, txtMar, txtHindi, txtMaths, txtScience 3 Buttons: Name: btnOK, btnNew, btnExit Text: OK, New, Exit 2 Groupbox: Text: Scores, Result 11 Labels: Text: RollNo, Name, English, Marathi, Hindi, Math, Science, Total, Percentage, Division, Result 4 Labels: To Display output for Total, Percentage, Division and Result use Labels. To change looks of these four labels set following properties: AutoSize: False BackColor: White BorderStyle: FixedSingle Text: Blank Name: lblTotal, lblPer, lblDiv, lblResult
  • 6. www.dotnetvideotutorial.com Step 3: Add event handlers for buttons • Double click on OK and code it as follow: private void btnOK_Click(object sender, EventArgs e) { int m1, m2, m3, m4, m5, total; float per; string div="", result=""; m1 = Convert.ToInt32(txtEng.Text); m2 = Convert.ToInt32(txtMar.Text); m3 = Convert.ToInt32(txtHindi.Text); m4 = Convert.ToInt32(txtSci.Text); m5 = Convert.ToInt32(txtMth.Text); total = m1 + m2 + m3 + m4 + m5; per = total * 100 / 500.0f; if (m1 >= 35 && m2 >= 35 && m3 >= 35 && m4 >= 35 && m5 >= 35) { result = "PASS"; if (per >= 60) div = "I"; else if (per >= 45) div = "II"; else div = "III"; } else { result = "FAIL"; div = "NA"; } lblTotal.Text = total.ToString(); lblPer.Text = per.ToString(); lblResult.Text = result; lblDiv.Text = div; } • Double click on New button and code it as follow: private void btnNew_Click(object sender, EventArgs e) {
  • 7. www.dotnetvideotutorial.com txtRollNo.Text = ""; txtName.Text = ""; txtEng.Text = ""; txtMar.Text = ""; txtHindi.Text = ""; txtMth.Text = ""; txtSci.Text = ""; lblTotal.Text = ""; lblPer.Text = ""; lblResult.Text = ""; lblDiv.Text = ""; txtRollNo.Focus(); } • Exit button: private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); }