Download presentation
Presentation is loading. Please wait.
1
מבוא לתכנות בWINDOWS ב#C
ד"ר אבי רוזנפלד
2
בניית הטופס ב#C
3
בניית הטופס
4
הוספת אובייקטים תעבוד עם הTOOLBAR והמאפיינים
5
שינוי המאפיינים אחרי הEVENT
.SHOW .HIDE .TEXT .ForeColor = Color.???
6
דוגמא
7
הקוד של הEVENT using ... namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) MessageBox.Show("Hello World","Title here!"); button1.Hide(); private void button2_Click(object sender, EventArgs e) textBox1.Text = "Hi there!"; button1.Show(); button1.ForeColor = Color.Green;
8
הטופס...
9
הקוד... namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) String word1 = textBox1.Text; String word2 = textBox2.Text; textBox3.Text = word1 + " added to " + word2 + " is " + word1+word2; MessageBox.Show(word1 + word2); //works! private void button2_Click(object sender, EventArgs e) // Double number1 = textBox1.Text; // "error cannot convert type string to double Double number1 = double.Parse(textBox4.Text); //converts! Double number2 = double.Parse(textBox5.Text); textBox6.Text = number1 + " added to " + number2 + " is " + number1 + number2; // MessageBox.Show(number1 + number2); Doesn't work! //MessageBox.Show((number1 + number2).ToString()); // a bit confusing... Double temp = number1 + number2; MessageBox.Show(temp.ToString());
10
קלט / פלט עם לוגיקה namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) int x = int.Parse(textBox1.Text); int y = int.Parse(textBox2.Text); if (x > y) textBox3.Text=(x + " is bigger than " + y); else if (x<y) textBox3.Text = (y + " is bigger than " + x); else textBox3.Text = ("They are the same!");
11
הטופס...
12
namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) int size = int.Parse(textBox1.Text); listBox1.Items.Clear(); //clears the listBox for (int i = 0; i < size; i++) string star = ""; for (int j = 0; j <= i; j++) // listBox1.Items.Add("*"); won't work! star += "*"; listBox1.Items.Add(star); // This will work! listBox2.Items.Add("Hi"); ListBox
13
הטופס...
14
CheckBox public partial class Form1 : Form { public Form1() InitializeComponent(); } private void button2_Click(object sender, EventArgs e) Application.Exit(); private void button1_Click(object sender, EventArgs e) int total = 0; if (checkBox1.Checked == true) total += 10; if (checkBox2.Checked == true) total += 5; if (checkBox3.Checked == true) total += 20; string temp = total.ToString(); textBox1.Text = temp;
15
הטופס
16
RadioBox namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) if (radioButton1.Checked == true) textBox1.Text = "Good"; if (radioButton2.Checked == true) textBox1.Text = "Better"; if (radioButton3.Checked == true) textBox1.Text = "Best"; if (radioButton4.Checked == true) textBox1.Text = "We love Shas!";
17
סיכום בתכנות אירועים, יש צורך לשאול:
מה יהיה האירוע (ומה יש בטופס כדי לקלוט אותו) מה יהיה התוצאה (ואיפה זה יופיע) מה הקוד מאחורי התוצאה סוגי אובייקים: LABEL לפלט או קלט (אבל בד"כ פלט) MsgBox , ListBox לפלט TextBox לקלט או פלט (אבל בד"כ קלט) כפתור להפעיל אירוע
18
תרגיל #1 לכתוב תכנית הקולטת סיסמה מהמשתמש. אם המשתמש הקיש את הסיסמה "BASIC" יש להציג את ההודעה "Welcome" ולסיים. אם המשתמש שגה בהקשת הסיסמה יש להציג את ההודעה "Wrong, Please try again". אם המשתמש שגה 3 פעמים (ברציפות) יש להציג את ההודעה "Wrong, cant continue. bye". כמה משתמים יש? איפה הם שמורים?
19
תרגיל #2 תרגיל #2: כתוב תוכנה הקולטת ערך אחד מתוך 5 RADIOBOX. באמצעות IF תפלוט משהו לכל אופציה (לא משנה מה).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.