You are on page 1of 14

‫برمجة مرئية ‪C#‬‬

‫المحاضرة األولى‬

‫علوم حاسوب تقنية معلومات‬


‫مستوى ثالث – ترم أول‬

‫‪Shima Ahmed‬‬
‫‪Sunnyhealer9@gmail.com‬‬
‫المشروع األول ‪:‬‬
‫‪ -1‬عند ظهور الفورم تظهر رسالة " أنقر على سطح الفورم نقره واحده بالمواس " ويظهر الفورم وسط الشاشة‪.‬‬
‫‪ -2‬عند النقر بالمواس نقره واحده على الفورم يتغير لون خلفية الفورم بلون مختلف في كل نقره (لون عشوائي)‪.‬‬
‫‪ -3‬عند ادخال نص في صندوق النص يتغير لون خلفية الصندوق الى اللون األصفر وعند حذف النص يعود للون‬
‫األبيض‪.‬‬
‫‪ -4‬عند النقر على زر اإلضافة يتم إضافة محتوى صندوق النص الى صندوق النص الثاني (‪ )txt_show‬حيث كل‬
‫نص بسطر جديد ويعود المؤشر لصندوق نص االدخال مع حذف النص السابق ليتم ادخال نص جديد‪.‬‬
‫‪ -5‬عند مرور النص فوق الزر إضافة يتغير لونه إلى اللون األحمر وعند االبتعاد يعد للون السابق الرمادي‪.‬‬
‫‪ -6‬تنفيذ اإلضافة بمجرد النقر على الزر ‪ Enter‬من الكيبورد‪.‬‬
‫‪ -7‬عند اغالق الفورم تظهر رسالة " مع السالمة "‪.‬‬
‫‪ -8‬عند الضغط على الزر خروج يقوم بإغالق النموذج‪.‬‬

‫جدول األدوات والخصائص‬


‫‪Tool‬‬ ‫‪Properties‬‬
‫‪Form1‬‬ ‫‪Name: frm_pro1‬‬
‫المشروع األول ‪Text:‬‬
‫‪Right to left: yes‬‬
‫‪Right to left layout: true‬‬
‫‪Accept button: btn_add‬‬
‫‪Label1‬‬ ‫‪Name: lbl_enter‬‬
‫أدخل النص ‪Text:‬‬
Textbox1 Name: txt_enter
Button1 Name: btn_add
Text: ‫إضافة‬
Textbox2 Name: txt_show
Multiline: true
Readonly: true
Button2 Name: btn_close
Text: ‫خروج‬

‫الكود البرمجي‬
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project_1_1
{
public partial class Frm_pro1 : Form
{
public Frm_pro1()
{
InitializeComponent();
}

private void Frm_pro1_Load(object sender, EventArgs e)


{
MessageBox.Show("‫;)"واحده مره الفورم سطح على انقر‬
this.CenterToScreen();
}

private void Frm_pro1_MouseClick(object sender, MouseEventArgs e)


{
Random r = new Random();
int x = r.Next(0, 255);
int y = r.Next(0, 255);
int z = r.Next(0, 255);
this.BackColor = Color.FromArgb(x, y, z);
}

private void txt_enter_TextChanged(object sender, EventArgs e)


{
if (txt_enter.Text != "")
txt_enter.BackColor = Color.Yellow;
else
txt_enter.BackColor = Color.White;
}

private void btn_add_Click(object sender, EventArgs e)


{
if (txt_enter.Text != " ")
{
txt_show.Text = txt_show.Text + txt_enter.Text + "\r\n"; // or Enviroment.newline
txt_enter.Focus();
txt_enter.Clear();
}
else
{
MessageBox.Show("‫;)"اوال النص أدخل‬
txt_enter.Focus();
}
}

private void btn_add_MouseEnter(object sender, EventArgs e)


{
btn_add.BackColor = Color.Red;
}

private void btn_add_MouseLeave(object sender, EventArgs e)


{
btn_add.BackColor = Color.Gray;
}

private void Frm_pro1_FormClosing(object sender, FormClosingEventArgs e)


{
MessageBox.Show("‫;)"السالمه مع‬
}

private void btn_close_Click(object sender, EventArgs e)


{
this.Close();
}
}
}
: ‫المشروع الثاني‬

‫جدول األدوات والخصائص‬


Tool Properties
Label1 Name: lbl_input
Text: ‫أدخل النص‬
Textbox1 Name: txt_input
Labe2 Name: lbl_fact
Visible: false
Labe3 Name: lbl_sum
Visible: false
Labe4 Name: lbl_sqrt
Visible: false
Button1 Name: btn_fact
Text: ‫المضروب‬
Button2 Name: btn_sum
Text: ‫المجموع‬
Button3 Name: btn_sqrt
Text: ‫جذر العدد‬
‫الكود البرمجي‬
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace lecture00
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

bool isnumeric(string txt)


{
int c = 0;
for (int i = 0; i < txt.Length; i++)
if (txt[i] > 48 && txt[i] < 57)
c++;
if(c==txt.Length)
return true;
return false;
}
int num;
private void btn_sum_Click(object sender, EventArgs e)
{
int sum = 0;
if (txt_no.Text != "")
{
num = int.Parse(txt_no.Text);
for (int i = 1; i <= num; i++)
sum += i;

lbl_sum.Text = sum.ToString();
lbl_sum.Visible = true;
}
else
{
MessageBox.Show("‫;)" العدد ادخل‬
txt_no.Focus();
txt_no.SelectAll();
}
}

private void btn_fact_Click(object sender, EventArgs e)


{
double fact = 1;

if (txt_no.Text != "")
{

num = int.Parse(txt_no.Text); ;
for (int i = 1; i <= num; i++)
fact *= i;

lbl_fact.Text = fact.ToString();
lbl_fact.Visible = true;
}
else
{
MessageBox.Show("‫;)" العدد ادخل‬
txt_no.Focus();
txt_no.SelectAll();
}
}
private void btn_sqrt_Click(object sender, EventArgs e)
{
if (txt_no.Text != "")
{
num = int.Parse(txt_no.Text);
lbl_sqrt.Text = Math.Sqrt(num).ToString();
lbl_sqrt.Visible = true;
}
else
{
MessageBox.Show("‫;)" العدد ادخل‬
txt_no.Focus();
txt_no.SelectAll();
}
}

private void txt_no_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled = true;
}
}
}

: ‫المشروع الثالث‬

‫الكود البرمجي‬
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ‫بوكس_جروب_الدخول_تسجيل‬
{
public partial class Form1 : Form
{
string [] password = {"111","222","kh20" };
public Form1()
{
InitializeComponent();
}

private void btn_enter_Click(object sender, EventArgs e)


{
int i = cmb1.SelectedIndex;
if (txt_password.Text == password[i])
{
MessageBox.Show("‫;)"بنجاح التسجيل تم‬
groupBox2.Visible = false;
groupBox1.Visible = true;
}
else
{
MessageBox.Show("‫;)"صحيحة غير المرور كلمة‬
txt_password.Clear();
txt_password.Focus();
}
}

private void btn_cancel_Click(object sender, EventArgs e)


{
this.Close();
}

private void btn_save_Click(object sender, EventArgs e)


{
int i = cmb2.SelectedIndex;
if (txt_old_pass.Text != password[i])
{
MessageBox.Show("‫;)"صحيحة غير المرور كلمة‬
}
else if(txt_new_pass.Text=="")
{
MessageBox.Show("‫;)"الجديدة المرور كلمة ادخل‬
txt_new_pass.Focus();
}
else if (txtnewpass2.Text== "")
{
MessageBox.Show("‫;)"للتأكيد المرور كلمة كتابة أعد‬
}
else if (txt_new_pass.Text != txtnewpass2.Text)
{
MessageBox.Show("‫;)"متطابقة غير المرور كلمة‬
}
else
{
password[i] = txt_new_pass.Text;
MessageBox.Show("‫;)"بنجاح المرور كلمة تغيير تم‬
txt_old_pass.Text = txt_new_pass.Text = txtnewpass2.Text = "";
}
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)


{
if(checkBox1.Checked)
txt_password.PasswordChar = Convert.ToChar(0);
else
txt_password.PasswordChar='*';
}

private void btn_back_Click(object sender, EventArgs e)


{
groupBox2.Visible = true;
groupBox1.Visible = false;
}

private void Form1_Load(object sender, EventArgs e)


{
groupBox2.Location = groupBox1.Location;
}
}
}

: ) ‫المشروع الرابع ( سؤال موجود بأحد نماذج الدكتور فهد‬

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ‫النموذج_سؤال‬
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
add.Visible = false;
sub.Visible = false;
mul.Visible = false;
div.Visible = false;
panel2.Visible = false;
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar < '0') || (e.KeyChar > '9'))
{
e.Handled = true;
MessageBox.Show("‫;)"فقط ارقام ادخال يمكنك‬
}
}

private void add_Click(object sender, EventArgs e)


{
if ((textBox1.Text.Trim() != "") && (textBox2.Text.Trim() != ""))
{
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) +
Convert.ToInt32(textBox2.Text));
}
else
MessageBox.Show("‫;)"رقما أدخل‬
}

private void sub_Click(object sender, EventArgs e)


{
if ((textBox1.Text.Trim() != "") && (textBox2.Text.Trim() != ""))
{
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) -
Convert.ToInt32(textBox2.Text));
}
else
MessageBox.Show("‫;)"رقما أدخل‬
}

private void mul_Click(object sender, EventArgs e)


{
if ((textBox1.Text.Trim() != "") && (textBox2.Text.Trim() != ""))
{
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) *
Convert.ToInt32(textBox2.Text));
}
else
MessageBox.Show("‫;)"رقما أدخل‬
}

private void div_Click(object sender, EventArgs e)


{
if ((textBox1.Text.Trim() != "") && (textBox2.Text.Trim() != ""))
{
if (textBox2.Text != "0")
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) /
Convert.ToInt32(textBox2.Text));
else
MessageBox.Show("error dvided by zero");
}
else
MessageBox.Show("‫;)"رقما أدخل‬
}

private void btnadd_Click(object sender, EventArgs e)


{
panel2.Visible = true;
add.Visible = true;
sub.Visible = false;
mul.Visible = false;
div.Visible = false;
label5.Text = "+";
}

private void btnsub_Click(object sender, EventArgs e)


{
panel2.Visible = true;
add.Visible = false;
sub.Visible = true;
mul.Visible = false;
div.Visible = false;
label5.Text = "-";
}

private void btnmul_Click(object sender, EventArgs e)


{
panel2.Visible = true;
add.Visible = false;
sub.Visible = false;
mul.Visible = true;
div.Visible = false;
label5.Text = "*";
}

private void btndiv_Click(object sender, EventArgs e)


{
panel2.Visible = true;
add.Visible = false;
sub.Visible = false;
mul.Visible = false;
div.Visible = true;
label5.Text = "/";
}

private void btnclose_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

You might also like