0% found this document useful (0 votes)
287 views34 pages

Namespace Public Partial Class Public: Form1

The document contains code for a Windows form application with multiple classes. It defines classes that create forms with buttons, text boxes, and labels. The buttons have click event handlers that perform actions like summing the values in text boxes, changing text box colors, generating new controls, and finding prime numbers.

Uploaded by

farhadvtc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
287 views34 pages

Namespace Public Partial Class Public: Form1

The document contains code for a Windows form application with multiple classes. It defines classes that create forms with buttons, text boxes, and labels. The buttons have click event handlers that perform actions like summing the values in text boxes, changing text box colors, generating new controls, and finding prime numbers.

Uploaded by

farhadvtc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

namespace class_1

{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
button1.ForeColor = Color.Green;
button1.Width = 40;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "Good luck";
}
private void button3_Click(object sender, EventArgs e)
{
int x, y, z;
x =int.Parse( textBox1.Text);
y=int.Parse(textBox2.Text);
z=x+y;
textBox3.Text = z.ToString() ;
// textBox3.Text = Convert.ToString(z);
}
}

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int i =1;
TextBox te1 = new TextBox();
TextBox te2 = new TextBox();
TextBox te3 = new TextBox();
TextBox te4 = new TextBox();
TextBox te5 = new TextBox();
TextBox te6 = new TextBox();
int prime(int x)
{
bool test = true;
while (test == true )
{
x++;
for (int j = 2; j <x ; j++)
{
if (x % j == 0) break;
if (j == x - 1) test = false;
}
}
return x;
} // ( )
public Form1()
{
InitializeComponent();
te1.Text = Convert.ToString(10);
Controls.Add(te1);
te1.Top = 50 + i * 25;
te1.Left = 300;
}
private void button2_Click(object sender, EventArgs e)
{
int x = int.Parse(te1.Text);
x = x + int.Parse(te2.Text);//sum
x = x + int.Parse(te3.Text);
x = x + int.Parse(te4.Text);
x = x + int.Parse(te5.Text);
x = x + int.Parse(te6.Text);
label1.Text = x.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
te2.Text = te1.Text;//copy
te3.Text = te1.Text;
te4.Text = te1.Text;
te5.Text = te1.Text;
te6.Text = te1.Text;
}
private void button4_Click(object sender, EventArgs e)
{
int x = int.Parse(te1.Text);
x += 2;
te2.Text = x.ToString();
x += 2;
te3.Text = x.ToString();
x += 2;

te4.Text = x.ToString();
x += 2;
te5.Text = x.ToString();
x += 2;
te6.Text = x.ToString();

}
private void button5_Click(object sender, EventArgs e)
{
te1.ForeColor = Color.Chocolate;
te2.ForeColor = Color.Red ;
te3.ForeColor = Color.Gold;
te4.ForeColor = Color.Green;
te5.ForeColor = Color.Blue;
te6.ForeColor = Color.Black;
}
private void button6_Click(object sender, EventArgs e)
{
int x = int.Parse(te1.Text);
x = prime(x);//
te2.Text = x.ToString();//
x = prime(x);
te3.Text = x.ToString();
x = prime(x);
te4.Text = x.ToString();
x = prime(x);
te5.Text = x.ToString();
x = prime(x);
te6.Text = x.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
i++;
if (i >= 7) i = 6;
switch (i)
{
case 1: Controls.Add(te1); te1.Top = 50 + i * 25; te1.Left
case 2: Controls.Add(te2); te2.Top = 50 + i * 25; te2.Left
case 3: Controls.Add(te3); te3.Top = 50 + i * 25; te3.Left
case 4: Controls.Add(te4); te4.Top = 50 + i * 25; te4.Left
case 5: Controls.Add(te5); te5.Top = 50 + i * 25; te5.Left
case 6: Controls.Add(te6); te6.Top = 50 + i * 25; te6.Left
}
}
private void button7_Click(object sender, EventArgs e)
{
if (i <= 1) i = 1;
switch (i)
{
case 1: Controls.Remove(te1); break;
case 2: Controls.Remove(te2); break;
case 3: Controls.Remove(te3); break;
case 4: Controls.Remove(te4); break;
case 5: Controls.Remove(te5); break;
case 6: Controls.Remove(te6); break;
}
i--;
}
}

=
=
=
=
=
=

300;
300;
300;
300;
300;
300;

break;
break;
break;
break;
break;
break;

namespace Class_2
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x = int.Parse(textBox1.Text);
for (int i = 0; i < x; i++)
{
Button b1 = new Button();
Controls.Add(b1);
b1.Text = "Finish"+i.ToString();
b1.Name = "bb";
b1.Left = 50;
b1.Top = 75+i*25;
b1.Width = 120;
}
for (int i = 0; i < x; i++)
{
TextBox t1 = new TextBox();
Controls.Add(t1);
t1.Left = 200;
t1.Top = 75 + i * 25;
t1.Width = 120;
}
for (int i = 0; i < x; i++)
{
Label l1 = new Label();
Controls.Add(l1);
l1.Left = 400;
l1.Top = 75 + i * 25;
l1.Width = 120;
l1.Text = "ll" + i.ToString();
}
}

namespace class_3
{

private void button1_Click(object sender, EventArgs e)


...
{
for (int i = 0; i < Controls.Count; i++)
if (Controls[i].Name == "tb1")
{
Controls.Remove(Controls[i]);
i--;
}
for (int i = 0; i < 3; i++)
{
TextBox tb;
tb = new TextBox();
Controls.Add(tb);
tb.Top = 50+i*25;
tb.Left = 50;
tb.Name = "tb1";
}
}
private void button2_Click(object sender, EventArgs e)
... Label ...
{
int sum=0;
try

{

for (int i = 0; i < Controls.Count; i++)

{

if (Controls[i].Name == "tb1")
..
sum += int.Parse(Controls[i].Text);

}

}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
label1.Text = sum.ToString();
}
private void button3_Click(object sender, EventArgs e)
controls
( ..... buttons textbox Label ) controls
{
this.Text = Controls.Count.ToString();
}

namespace class_4
{
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 2; i++)
{
Button b1 = new Button();
Controls.Add(b1);
b1.Left = 50;
b1.Top = 50 + i * 25;
b1.Width = 130;
b1.Name = "block" + i.ToString();
if (i == 0)
{
b1.Click += new EventHandler(b1click);
b1.Text = "Showing message box" ;
}
if (i == 1)
{
b1.Click += new EventHandler(b1click2);
b1.Text = "Generat textbox";
}
if (i == 2)
{
b1.Click += new EventHandler(tv);
b1.Text = "Summation";
}
}
}
private void b1click(object sender, EventArgs e)
{
MessageBox.Show("Your button is programmed");
}
private void b1click2(object sender, EventArgs e)
{
for (int i = 0; i < 2; i++)
{
TextBox t1 = new TextBox();
Controls.Add(t1);
t1.Name = "tt";
t1.Location = new Point(190, 90 + i * 25);
}
}
private void tv(object sender, EventArgs e)
{
int sum=0;
Label l1 = new Label();
Controls.Add(l1);
l1.Location = new Point(100, 150);
for (int j = 0; j < Controls.Count; j++)
{
if (Controls[j].Name == "tt") sum += int.Parse(Controls[j].Text);
}
l1.Text = sum.ToString();
}

namespace homework4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 3; i++)
{
Button b = new Button();
Controls.Add(b);
b.Location = new Point(100, 75 + i * 25);
b.Name = i.ToString();
b.Width=100;
}
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i].Name == "1")
{
Controls[i].Text = "genraet text box";
Controls[i].Click +=new EventHandler(clik_g);
}
if (Controls[i].Name == "2")
{
Controls[i].Text = "sum";
Controls[i].Click += new EventHandler(clik_s);
}
if (Controls[i].Name == "3")
{
Controls[i].Text = "remove";
Controls[i].Click += new EventHandler(clik_r);
}
}
}
private void clik_g(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
TextBox t = new TextBox();
Controls.Add(t);
t.Location = new Point(300, 75 + i * 25);
t.Name = "tt";
}
}
private void clik_s(object sender, EventArgs e)
{
int sum = 0;
try
{
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i].Name == "tt")
{
sum += int.Parse(Controls[i].Text);
}

}
Label L = new Label();
Controls.Add(L);
L.Location = new Point(300, 200);
L.Text = "sum = "+sum.ToString();
L.Name = "L";
int av = sum / 3;
Label L2 = new Label();
Controls.Add(L2);
L2.Location = new Point(300, 225);
L2.Text = "avarage = " + av.ToString();
L2.Name = "L";

}
catch
{
MessageBox.Show(";)"
}

}
private void clik_r(object sender, EventArgs e)
{
for (int i = 0; i <Controls.Count; i++)
{
if (Controls[i].Name == "tt" || Controls[i].Name == "L")
{
Controls.Remove(Controls[i]);
i--;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Text = Controls.Count.ToString();
}

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

private void button1_Click(object sender, EventArgs e)


{
int[] x;
x = new int[3]{2,4,80};
foreach (int q in x)
{
TextBox t1 = new TextBox();
Controls.Add(t1);
t1.Top=75+g*25;
t1.Text = q.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
// List<int> l1 = new List<int>();
List<int> L1;
L1 = new List<int>();
L1.Add(70);
L1.Add(10);
L1.Add(65);
L1.RemoveAt(1);
L1.Remove(10);
int i=0;
foreach (int u in l1)
{
TextBox t1 = new TextBox();
Controls.Add(t1);
t1.Top = 75 + i * 25;
t1.Left = 125;
t1.Text = u.ToString();
i++;
}
}

namespace homework_5
{
public partial class Form1 : Form
{
int[] x; int[] y; int[] z;
int n;
List<int> x1; List<int> y1; List<int> z1;//
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int j = 0; int j1 = 0;
n = int.Parse(textBox1.Text);
Label L = new Label();
L.Text = "x Array";
L.Name = "x Array";
Controls.Add(L);
L.Location = new Point(button1.Left, button1.Bottom + button1.Height * j++);
Label L2 = new Label();
L2.Text = "y Array";
L2.Name = "y Array";
Controls.Add(L2);
L2.Location = new Point(button1.Left + button1.Width, button1.Bottom +
button1.Height * j1++);
for (int i = 0; i < n; i++)
{TextBox t1 = new TextBox();
t1.Name = "tt";
t1.Location = new Point(button1.Left, button1.Bottom + button1.Height *
j++);
Controls.Add(t1);
}
for (int i = 0; i < n; i++)
{TextBox t2 = new TextBox();
t2.Name = "tt2";
t2.Location = new Point(button1.Left + button1.Width, button1.Bottom +
button1.Height * j1++);
Controls.Add(t2);
}
}
catch
{
MessageBox.Show(";)"!!!!
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
int k1 = 0, k2 = 0;
x = new int[int.Parse(textBox1.Text)];
y = new int[int.Parse(textBox1.Text)];
z = new int[int.Parse(textBox1.Text)];
for (int i = 0; i < Controls.Count; i++)
{

if (Controls[i].Name == "tt")
{
x[k1] = int.Parse(Controls[i].Text);
k1++;
}
if (Controls[i].Name == "tt2")
{
y[k2] = int.Parse(Controls[i].Text);
k2++;
}

}
MessageBox.Show("


}
catch
{
MessageBox.Show(";)"
}

" + n + "

");

}
private void button3_Click(object sender, EventArgs e)
{
int i = 0;
Label L3 = new Label();
L3.Text = " Z = x * y ";
Controls.Add(L3);
L3.Location = new Point(button3.Left, button3.Bottom + button3.Height * i);
if (x != null)
{
for (; i < n; i++)
{
TextBox t2 = new TextBox();
t2.Name = "tt3";
t2.Location = new Point(button3.Left, L3.Bottom + L3.Height * i);
Controls.Add(t2);
z[i] = x[i] * y[i];
t2.Text = z[i].ToString();
}
}
}
private void button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i].Name == "tt" || Controls[i].Name == "tt2" || Controls[i].Name
== "x Array" || Controls[i].Name == "y Array")
{
Controls[i].Dispose();
i--;
}
}
}
private void button5_Click(object sender, EventArgs e)
{
x1 = new List<int>();
y1 = new List<int>();
int countx = 0;
int county = 0;
try
{

for (int i = 0; i < Controls.Count; i++)


{
if (Controls[i].Name == "tt")
{
x1.Add(int.Parse(Controls[i].Text));
countx++;
}
if (Controls[i].Name == "tt2")
{
y1.Add(int.Parse(Controls[i].Text));
county++;
}
}

}
catch
{
MessageBox.Show(";)"
}
MessageBox.Show("list " + " x

" + countx + "

y " + county);

private void button6_Click(object sender, EventArgs e)


{
z1 = new List<int>();
for (int i = 0; i < n; i++)
{ z1.Add( y1[i] * x1[i]);
TextBox tt3 = new TextBox();
Controls.Add(tt3);
tt3.Location = new Point(button6.Left, button6.Bottom + button6.Height * i);
tt3.Text = z1[i].ToString();
}
}

namespace Class_6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TextBox[] x;

private void button1_Click(object sender, EventArgs e)


{
x=new TextBox[3];
for (int i = 0; i < 3; i++)
{
x[i] = new TextBox();
x[i].Left = button1.Left;
x[i].Top = button1.Bottom + button1.Height * i;
x[i].Width = button1.Width;
Controls.Add(x[i]);
x[i].Text = i.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
int sum = 0;
for (int i = 0; i < x.Length; i++)
sum += int.Parse(x[i].Text);
MessageBox.Show(sum.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
int t = int.Parse(textBox1.Text);
Controls.Remove(x[t]);
}

private void button4_Click(object sender, EventArgs e)


{
int t = int.Parse(textBox1.Text);
Controls.Add(x[t]);
}

namespace class_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Button b = sender as Button;
textBox1.Text = b.Text;
}
}

}//

b button1

namespace homwork_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int sum = 0;
List <int> x = new List<int>();
private void button1_Click(object sender, EventArgs e)
{
int n = 1;
for (int j=1; j<=10; j++){
for (int i = 1; i <=10; i++)
{
Button b = new Button();
Controls.Add(b);
b.Name = "b";
b.Text = n.ToString();
b.Top = button1.Bottom + i * 25;
b.Left = button1.Left + j * 75;
n++;
b.Click +=new EventHandler(b_Click);
}
}
}
private void b_Click(object sender, EventArgs e)
{
Button b1= sender as Button;
textBox1.Text = b1.Text;
sum += int.Parse(b1.Text);
label1.Text = sum.ToString();
if (sum < 200)
{
b1.BackColor = Color.Red;
}
else
b1.BackColor = Color.Blue;

}
private void button2_Click(object sender, EventArgs e)
{
x.Add(int.Parse(textBox1.Text));
}
private void button3_Click(object sender, EventArgs e)
{
int i = 0;
foreach (int s in x)
{
TextBox t = new TextBox();
Controls.Add(t);
t.Location = new Point(button3.Left, button3.Bottom + 25 * i++);
t.Text = s.ToString();
}
}
private void button1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 'a')
MessageBox.Show("jhjhj");

namespace homework_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Button b1 = new Button();
b1.Location = new Point(150, 25);
Controls.Add(b1);
b1.Click+=new EventHandler(b1_Click);
b1.Text = "genrate four buttons";
b1.Width = 150;
}
private void b1_Click(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++)
{
Button b = new Button();
b.Location = new Point(0, 0 + i * 50);
Controls.Add(b);
b.Text = i.ToString();
b.Name = i.ToString();
b.Click += new EventHandler(Form1_Click);
}

}
private void Form1_Click(object sender, EventArgs e)
{
Button bb = sender as Button;
bb.Left += bb.Width *int.Parse(bb.Text) ;
}

sender ( controls)

namespace class_8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(! Char.IsDigit(e.KeyChar))
e.Handled=true;
TextBox t = new TextBox();
Controls.Add(t);
t.Text = e.KeyChar.ToString();
t.Location = new Point(button1.Left, button1.Bottom + button1.Height * i++);
}
int k=0,j = 0,m=0;
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
TextBox t = new TextBox();
Controls.Add(t);
t.Text = e.KeyCode.ToString();
t.Location = new Point(button2.Left, button2.Bottom + button2.Height * j++);
TextBox tdata = new TextBox();
Controls.Add(tdata);
tdata.Text = e.KeyData.ToString();
tdata.Location = new Point(button3.Left, button3.Bottom + button3.Height * k++);
TextBox tvalue = new TextBox();
Controls.Add(tvalue);
tvalue.Text = e.KeyValue.ToString();
tvalue.Location = new Point(button4.Left, button4.Bottom +
button4.Height * m++);
}
}
}

namespace homework_9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int w = 0, h =0 , s = 0;

private void button1_KeyDown(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.S) //
{
button1.Left = button1.Left + 1;
button1.BackColor = Color.Blue;
if (button1.Right == 300 + w)
{
this.Width = this.Width + 1;
w++;
}
}
if (e.KeyData == (Keys.S | Keys.Control))//
{
button1.Left = button1.Left + 5;
button1.BackColor = Color.Blue;
if (button1.Right >= 300 + w)
{
this.Width = this.Width + 5;
w += 5;
}
}
if (e.KeyCode == Keys.A)//
{
button1.Left = button1.Left - 1;
button1.BackColor = Color.Green;
}
if (e.KeyData == (Keys.A | Keys.Control))//
{
button1.BackColor = Color.Green;
button1.Left = button1.Left - 5;
}
if (e.KeyCode == Keys.W)//
{
button1.Top = button1.Top - 1;
button1.BackColor = Color.Yellow;
}
if (e.KeyData == (Keys.W | Keys.Control))//
{
button1.Top = button1.Top -5;
button1.BackColor = Color.Yellow;
}

if (e.KeyCode == Keys.Z)//
{
button1.Top = button1.Top + 1;
button1.BackColor = Color.White;
if (button1.Bottom == 300 + h)
{
this.Height = this.Height + 1;
h++;
}
}
if (e.KeyData == (Keys.Z | Keys.Control))//
{
button1.Top = button1.Top + 5;
button1.BackColor = Color.White;
if (button1.Bottom >= 300 + h)
{
this.Height = this.Height + 5;
h += 5;
}
}
if (button1.Right >= 1370)//
button1.Left = 0;
if (button1.Bottom >= 700)// //
button1.Top = 0;
for (int i = 0; i < Controls.Count; i++) //
{
if (button1.Top==Controls[i].Top && button1.Left==Controls[i].Left && Controls[i].Name=="b")
{
s++;
label2.Text = s.ToString();
Controls[i].Dispose();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int name = 1;
for (int i= 0 ; i<= 2; i++)//
for (int j = 1; j <= 3; j++)
{
Button b = new Button();
b.Size = button1.Size;
b.Location = new Point(100 + i*150,100 + j*150);
b.Name = "b";
b.Text = name.ToString();
name++;
b.BackColor = button1.BackColor;
b.ForeColor = button1.ForeColor;
Controls.Add(b);
}
}
private void button1_KeyUp(object sender, KeyEventArgs e)
{
button1.BackColor = Color.Black;//
}
DialogResult d = DialogResult.yes;
private void button2_Click(object sender, EventArgs e)
{
if (d== MessageBox.Show("" , "worning",MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation))
this.Close();
}
}
}

using Microsoft.VisualBasic;

namespace class_9
{
private void button1_Click(object sender, EventArgs e)
{
DialogResult d1;
d1 = DialogResult.Yes;
d1= MessageBox.Show("Quit game","Game", MessageBoxButtons.YesNoCancel
,MessageBoxIcon.Question);
if (d1 == DialogResult.Yes) Close();
if (d1 == DialogResult.No) MessageBox.Show("the No button clicked");
}
private void button2_Click(object sender, EventArgs e)
{
string name;
name=Interaction.InputBox("Enter your name");
MessageBox.Show("The entered name is : " + name);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
int x, y, z;
if (textBox1.Text == "")
x = 0;
else x = int.Parse(textBox1.Text);
if (textBox2.Text == "")
y = 0;
else y = int.Parse(textBox2.Text);
if (textBox3.Text == "")
z = 0;
else z = int.Parse(textBox3.Text);
label1.Text = (x + y + z).ToString();
}
Button b1 = new Button();
private void textBox4_KeyUp(object sender, KeyEventArgs e)
{
b1.Top = int.Parse(textBox4.Text);
Controls.Add(b1);
}
private void textBox5_KeyUp(object sender, KeyEventArgs e)
{
if (textBox5.Text == "") b1.Left = 0;
else b1.Left = int.Parse(textBox5.Text);
}
}
}

using System.IO;

namespace class_10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
if(opf.ShowDialog()==DialogResult.OK)
{
StreamReader sr = new StreamReader(opf.FileName);
textBox1.Text=sr.ReadLine();
textBox2.Text = sr.ReadLine();
}
}
private void button2_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("d:\\ali.txt");
textBox3.Text = sr.ReadToEnd();
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saf = new SaveFileDialog();
if (saf.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saf.FileName);
sw.WriteLine(textBox1.Text);
sw.Close();
}
//(streamReader) ( streamWriter ) class
-----------------------------------------------------------------------------private void button5_Click(object sender, EventArgs e)
ali {
b
FileStream fs = File.OpenRead(@"d:\ali.txt");
byte[] b = new byte[fs.Length];
fs.Read(b, 0, b.Length);
rr2

FileStream fw = File.OpenWrite(@"d:\rr2.txt");

fw.Write(b, 0, 5);
fw.Close();
}
}
}//---------(FileStream ) class

using System.IO;
namespace homework_10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream f = File.OpenRead("d:\\a.txt");
byte[] b = new byte[f.Length];
f.Read(b, 0, 250);
FileStream f1 = File.OpenWrite("d:\\b.txt");
f1.Write(b, 0, 50);
f1.Close();
FileStream f2 = File.OpenWrite("d:\\c.txt");
f2.Write(b, 50, 100);
f2.Close();
FileStream f3 = File.OpenWrite("d:\\d.txt");
f3.Write(b, 100, 150);
f3.Close();
FileStream f4 = File.OpenWrite("d:\\e.txt");
f4.Write(b, 150, 200);
f4.Close();

FileStream f5 = File.OpenWrite("d:\\f.txt");
f5.Write(b, 200, 250);
f5.Close();

-:

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

private void button1_Click(object sender, EventArgs e)


{
Graphics gr = Graphics.FromHwnd(this.Handle);
Pen p=new Pen(Color.Green);
gr.DrawLine(p, 20, 20, 200, 20);
Pen p1 = new Pen(Color.Red, 4);
gr.DrawLine(p1, 20, 40, 200, 40);
//for rectangle
gr.DrawRectangle(p, 20, 60, 200, 100);
p.Color = Color.GreenYellow;
p.Width += 1;
Rectangle rc = new Rectangle();
rc.Height = 30;
rc.Width = 200;
rc.Location = new Point(20, 220);
//for arc
p.Color = Color.Red;
gr.DrawArc(p, rc, 0, 180);

}
private void button2_Click(object sender, EventArgs e)
{
Graphics gr = Graphics.FromHwnd(Handle);
Image i = Image.FromFile(@"D:\sharp.jpg");

gr.DrawImage(i, 0, 0);

private void button3_Click(object sender, EventArgs e)


{
Graphics gr = Graphics.FromHwnd(Handle);
Image i = Image.FromFile(@"D:\ya.jpg");
Rectangle rc = new Rectangle();
rc.Height = 60;
rc.Width = 200;
for (int ii = 20; ii < 400; ii++)
{

rc.Location = new Point(ii, ii);

gr.DrawImage(i, rc);
}
}
private void button4_Click(object sender, EventArgs e)
{
Graphics gr = Graphics.FromHwnd(Handle);
SolidBrush sb = new SolidBrush(Color.Red);
Font f=new Font("Times New Roman", 18, FontStyle.Italic);
gr.DrawString("C# lecture is very easy and funy", f, sb, 350, 50);
}

private void button5_Click(object sender, EventArgs e)


{
Graphics gr = Graphics.FromHwnd(this.Handle);
for (int i = 0; i < 255; i++)
{
for (int j = 0; j < 255; j++)
{
Pen p = new Pen(Color.FromArgb(25, 50, i, j));
gr.DrawLine(p, i, j, i + j, i + j);
}
}
}

}
using System.IO;

namespace class_12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int k = 0, m = 0;
private void button1_Click(object sender, EventArgs e)
{
string[] drivnames = Environment.GetLogicalDrives();
foreach(string driv in drivnames)
{
DriveInfo drv = new DriveInfo(driv);
if (drv.IsReady)
{
TextBox t1 = new TextBox();
t1.Location = new Point(button6.Left, button6.Bottom +
button6.Height * k++);
Controls.Add(t1);
t1.Text = drv.Name;
TextBox t2 = new TextBox();
t2.Location = new Point(button5.Left, button5.Bottom +
button5.Height * m++);
Controls.Add(t2);
t2.Text = drv.TotalSize.ToString();

DirectoryInfo dr = drv.RootDirectory;
CheckAll(dr);
}

private void button2_Click(object sender, EventArgs e)


{
string path = "d:\\aa\\";
DirectoryInfo df = new DirectoryInfo(@"d:\");
FileInfo[] fi = df.GetFiles();
foreach (FileInfo f in fi)
{
f.CopyTo(path + f.ToString(), true);
//f.MoveTo.......
//f.Delete();
}

}
int i = 0;
private void button4_Click(object sender, EventArgs e)
{
DirectoryInfo d1 = new DirectoryInfo(@"c:\first\second\");
if (!d1.Exists) d1.Create();
// FileInfo f1 = new FileInfo(d1+"easy.txt");
FileInfo f1 = new FileInfo(@"c:\first\second\easy.txt");

if (!f1.Exists) MessageBox.Show("the files was created because it's not avilable");


}

File.AppendAllText(f1.ToString(), "this is line


+ i++.ToString() + Environment.NewLine);

"

private void button3_Click(object sender, EventArgs e)


{
FileStream fs = File.OpenRead(@"d:\y1.txt");
byte[] b = new byte[fs.Length];
fs.Read(b, 0, b.Length);

FileStream fsw = File.OpenWrite(@"d:\y2.txt");


fsw.Write(b, 0, b.Length);
fsw.Close();

private void button7_Click(object sender, EventArgs e)


{
DirectoryInfo dd=new DirectoryInfo(@"D:\rrr\");
FileInfo[] fl = dd.GetFiles();
foreach (FileInfo f in fl)
MessageBox.Show(f.FullName);
}

void CheckAll(DirectoryInfo dir)


{
FileInfo[] files=null;
try
{
files = dir.GetFiles("*.*");
}
catch (UnauthorizedAccessException ex ) { }

if (files != null)
{
foreach (FileInfo ff in files)
MessageBox.Show(ff.FullName);
}
DirectoryInfo[] directories = null;
try
{
directories = dir.GetDirectories();
}
catch (UnauthorizedAccessException)
{ }
if (directories != null)
{
foreach (DirectoryInfo dd in directories)
CheckAll(dd);
}

}
--------------------------------------------------------------------------------------------using System.IO;
namespace homework_FlashMemory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string s1, s2="",s3,ss;
private void button1_Click(object sender, EventArgs e)
{
CheckBox[] x = new CheckBox[]
{
checkBox1,checkBox2,checkBox3,checkBox4,
checkBox5,checkBox6,checkBox7}
for (int i = 0; i < 7; i++)
{
if (x[i].Checked)
{ ss = x[i].Text;
MessageBox.Show(" Copying from drive "+ss);
DriveInfo dd = new DriveInfo(ss);
if (dd.IsReady )
{
DirectoryInfo dir = dd.RootDirectory;
// DirectoryInfo dir=new DirectoryInfo(@"H:\big");
checkAll(dir);
}
}
}
}

void checkAll(DirectoryInfo folder)


{
RadioButton[] rb = new RadioButton[]{radioButton1,radioButton2,radioButton3,dioButton4,
radioButton5,radioButton6,radioButton7};
RadioButton[] rbx = new RadioButton[]{radioButton8,radioButton9,radioButton10,radioButton11,};
for (int w = 0; w < 4; w++)
if(rbx[w].Checked)
{
string str = rbx[w].Text;//
FileInfo[] files = null;
DirectoryInfo[] dir = null;
try
{
files = folder.GetFiles(str);
}
catch (UnauthorizedAccessException ex)
{
// MessageBox.Show(ex.Message);
}
for (int i = 0; i < 7; i++)
if (rb[i].Checked) s2 = rb[i].Text;
if (s2 == "") MessageBox.Show("Select the target drive");
else
{
string s1 = folder.FullName;
s1 = s1.Remove(0, 3);
// s2 = @"J:\";
s3 = s2 + s1 + "\\";
DriveInfo dt = new DriveInfo(s2);
if (new DriveInfo(s2).IsReady)
{
DirectoryInfo dirEmp = new DirectoryInfo(s3);
if (!dirEmp.Exists) dirEmp.Create();
if (files != null)
{
foreach (FileInfo f in files)
{
f.CopyTo(s3 + f.Name, true);
}
}
try
{
dir = folder.GetDirectories();
}
catch (UnauthorizedAccessException) { }
if (dir != null)
{
foreach (DirectoryInfo diiir in dir)
checkAll(diiir);
}

}
else MessageBox.Show("The " + s2 + " as target drive is not ready");
}
// else MessageBox.Show("Please select a file type");

namespace class_13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics gr = Graphics.FromHwnd(Handle);
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "Image files|*e*.jpg;d?????.bmp";

//opf.Filter = "All files|*.*|Acrobat files|*.pdf|Word files|*.doc;*.docx|Picture


files|*.jpg;*.bmp";
i
if (opf.ShowDialog() == DialogResult.OK)
{
Image im = Image.FromFile(opf.FileName);
A
gr.DrawImage(im, 20, 20, 300, 250);
}
R
}
G
private void button3_Click(object sender, EventArgs e)
{
B
Graphics gr = Graphics.FromHwnd(this.Handle);
Image im = Image.FromFile("d:\\desert.jpg");
// gr.DrawImage(im, 20, 20, 300, 250);
Bitmap bp = new Bitmap(im);
int[,,] pixval = new int[bp.Width, bp.Height, 4];
for (int i = 0; i < bp.Width; i++)

for (int j = 0; j < bp.Height; j++)
{
im -
Color cr = bp.GetPixel(i, j);
-
int k = 0;
pixval[i, j, k++] = cr.A;
bp bitmap
pixval[i, j, k++] = cr.R;
bp -
pixval[i, j, k++] = cr.G;

pixval[i, j, k++] = cr.B;
//if (cr.B > 200) pixval[i, j, 3] = 50;
bp2 bitmap -
//if (cr.B > 50) pixval[i, j, 3] = 50;
) ( -
// MessageBox.Show(cr.ToString());
bp2
}

Bitmap bp2 = new Bitmap(bp.Width, bp.Height);


for (int i = 0; i < bp2.Width; i++)
for (int j = 0; j < bp2.Height; j++)
{
int k = 0;
int A = pixval[i, j, k++];
int R = pixval[i, j, k++];
int G = pixval[i, j, k++];
int B = pixval[i, j, k++];
bp2.SetPixel(i, j, Color.FromArgb(A, R, G, B));
}
gr.DrawImage(bp2, 400, 20, 300, 250);

bp2 -

using System.Drawing.Printing;
namespace class_14
{
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Text = "goal";
// f2.f1 = this;
f2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black), 200, 300, 10, 40);
}
private void button3_Click(object sender, EventArgs e)
{
PrintDialog pdg = new PrintDialog();
if (pdg.ShowDialog() == DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings = pdg.PrinterSettings;
pdg.Document = pd;
pd.PrintPage += new PrintPageEventHandler(ptttp);
//MessageBox.Show("we ready to print");
pd.Print();
}
}
private void ptttp(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Red), 500, 300, 10, 40);
}
}
}

using System.Drawing.Printing;
namespace class_15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void printDocument1_PrintPage(object
printDocument1_PrintPage
sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Let's
Let's go
go", new Font("Arial", 16, FontStyle.Regular),
Brushes.Black, 10, 10);
}
private void button1_Click(object
button1_Click(
sender, EventArgs e)
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
// ( print Document1) ( print dialog )
properties ... -:
private void button2_Click(object
button2_Click(
sender, EventArgs e)
{
x = 1;
PrintDialog pdg = new PrintDialog();
if (pdg.ShowDialog() == DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings = pdg.Printe
pdg.PrinterSettings;//
pd.PrintPage += new PrintPageEventHandler(ptt);
pd.Print();
}
}
int x=1;
private void ptt(object
object sender, PrintPageEventArgs evv)
{
if(x==1)
evv.Graphics.DrawString(textBox1.Text,

new Font("Arial"
"Arial", 16, FontStyle.Regular),
textBox1
Brushes.Black, 10, 10);

if(x==2)
evv.Graphics.DrawString(textBox2.Text,

new Font("Arial"
"Arial", 16, FontStyle.Regular),
textBox2
Brushes.Black, 10, 10);
if (x < 2) evv.HasMorePages = true;

x++;
}
}
} // ( print Document1) ( print dialog )

using System.Drawing.Printing;
using System.IO;

namespace homework_14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int count = 0 ,x = 0;
StreamReader r = new StreamReader("d:\\tt.txt");

private void button1_Click(object sender, EventArgs e)


{
StreamReader r = new StreamReader("d:\\tt.txt");
while (!r.EndOfStream)
{
r.ReadLine();
count++;
}
if (printDialog1.ShowDialog()==DialogResult.OK)
printDocument1.Print();
}
///////////////////////////////////////////////////////////////////////////////////
void printDocument1_PrintPage(objectsender,system.Drawing.Printing.PrintPageEventArgs e)
{
Pen p = new Pen(Color.Black);
for (int i = 0; i < 15 && x < count; i++)
{
e.Graphics.DrawString(r.ReadLine(), new Font("tahoma", 18, FontStyle.Bold),
new SolidBrush(Color.Red), 100, 100 + (50 * i));
e.Graphics.DrawLine(p, 100, 100 + (50 * i), 600, 100 + (50 * i));//
e.Graphics.DrawLine(p, 100, 150 + (50 * i), 600, 150 + (50 * i));//
x++;
e.Graphics.DrawLine(p, 100, 100+(50*i), 100, 150+(i*50));
e.Graphics.DrawLine(p, 350, 100 + (50 * i), 350, 150 + (50 * i));
for (int j = 0; j < 5; j++)
e.Graphics.DrawLine(p, 400 + (50 * j), 100 + (50 * i), 400 + (50 * j), 150 + (50 * i));
}
if (x < count) e.HasMorePages = true;
}
}

d:\\tt.txt

count -
(printDialog1) -
-
-
Count -

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

//

private void button1_Click_1(object sender, EventArgs e)


{ // screen capture
// Bitmap bp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Right);
Bitmap bp = new Bitmap(300, 300);
Graphics gr = Graphics.FromImage(bp);
gr.CopyFromScreen(0, 0, 0, 0, bp.Size);
bp.Save("d:\\dd.bmp");
}
//


Point start;

private void Form1_MouseDown(object sender, MouseEventArgs e)


{
start = e.Location;
}

private void Form1_MouseMove(object sender, MouseEventArgs e)


{
Graphics gr = Graphics.FromHwnd(Handle);
Pen p = new Pen(Color.Red);
if (e.Button == MouseButtons.Left)
{
gr.DrawLine(p, start, e.Location);
start = e.Location;
}
}


- Microsoft access
-

- ) ( ) ( En.
- c#
-
- view other window server Explorer ) . ( ctrl + alt + s
-


-
ok
- change

- Browse
- Advanced
-

using System.Data.OleDb;

namespace _1database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds;
OleDbConnection con;
OleDbDataAdapter da;
private void button1_Click(object sender, EventArgs e)
{

Data grid view

ds = new DataSet();
con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
DataSource=C:\Users\hP\Documents\7.accdb");
da = new OleDbDataAdapter("select * from tab1",con);
con.Open();
da.Fill(ds,"all");

private void button2_Click(object sender, EventArgs e)


{
dataGridView1.DataSource= ds;
dataGridView1.DataMember="all";
}

( paste)

You might also like