STAR ACADEMY OF TECHNOLOGY AND MANAGEMENT
INDORE
COMPUTER SCIENCE & ENGINEERING
DOTNET TECNOLOGY(CS-406)
LAB MANUAL
Submitted By :
Name : RANJIT KUMAR NAHAK
Session : Jan 2014-Jun 2014
Dept. : CSE, SATM
1) W.A.P to perform basic arithmetic calculation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add
{
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter first nos.");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second no.");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("add is :{0}", a + b);
Console.WriteLine("sub is :{0}",a-b);
Console.WriteLine("multiis :{0}",a*b);
Console.WriteLine("devi is :{0}",a/b);
Console.ReadLine();
}
}
}
OUTPUT
2) W.A.P to interchange the value of 2 variables without using third variable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace swap
{
class Program
{
static void Main(string[] args)
int a = 6;
int b = 7;
Console.WriteLine("the numbers before swapping a={0} and b={1}",a,b);
a = a + b;
b = a - b;
a = a - b;
Console.WriteLine("the numbers after swapping a={0} and b={1}", a,
b); Console.Read();
}
}
}
OUTPUT
3) W.A.P to display array elements & their sum.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace array
{
class Program
{
static void Main(string[] args)
{
int[] num = { 10, 20, 30, 40 }; int n =
num.Length; Console.WriteLine("array
elements"); for (int i = 0; i < n; i++)
{ Console.WriteLine(num[i]);
}
int sum = 0;
for (int i = 0; i < n; i++)
{ sum = sum + num[i];
} Console.WriteLine("sum"+sum);
Console.Read();
}
}
}
OUTPUT
4) W.A.P to input array elements & sort them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace arrayip
{
class Program
{
static void Main(string[] args)
int i, j, temp;
int[] ar = new int[5];
Console.WriteLine("Enter the elements of array");
for (i = 0; i < ar.Length; i++)
{
ar[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Sorted array is: ");
{
for (i = 0; i < ar.Length; i++)
{
for (j = i + 1; j < ar.Length; j++)
{
if (ar[i] > ar[j])
{
temp = ar[i]; ar[i] =
ar[j]; ar[j] = temp;
}
}
}
for (i = 0; i < ar.Length; i++)
{
Console.Write(ar[i]);
Console.ReadLine();
}
}
}
}}
OUTPUT
5) W.A.P using c lass.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
{
class Program
{
class student
{
String nm, dep, gen;
public void setdata()
{
Console.WriteLine("Eter Name"); nm =
Console.ReadLine();
Console.WriteLine("Enter Dept"); dep =
Console.ReadLine();
Console.WriteLine("Enter gender"); gen =
Console.ReadLine();
}
public void putdata()
{
Console.WriteLine("Name " +nm);
Console.WriteLine("DEPT " +dep);
Console.WriteLine("Gender " +gen);
}
}
static void Main(string[] args)
{
student stu = new student();
stu.setdata(); stu.putdata();
Console.ReadLine();
}
}
}
OUTPUT
6) W.A.P to print fibonacci series.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fibonic_series
{
class Program
{
static void Main(string[] args)
{
int a, b, c,n;
a=0;
b=1;
Console.WriteLine("Enter Limit: ");
n =
Convert.ToInt32(Console.ReadLi
ne()); Console.WriteLine( a);
Console.WriteLine( b);
for(int i=3;i<=n;i++)
{
c = a + b;
a = b; b = c;
Console.Writ
eLine(c);
}
Console.ReadLine();
}
}
}
OUTPUT
7) W.A.P using function overloading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace funover
{
class Program
{
class worker
{
public void salary(int a, int b)
{
int total, bonus;
Console.Write("Enter first bonus: ");
bonus = Convert.ToInt32(Console.ReadLine());
total = bonus + a + b; Console.WriteLine();
Console.WriteLine("Total salary is: "+total);
Console.WriteLine();
}
public void salary(int a)
{
int total, bonus;
Console.Write("Enter second bonus: ");
bonus = Convert.ToInt32(Console.ReadLine());
total = bonus + a; Console.WriteLine();
Console.WriteLine("Total salary is: "+total);
}
}
static void Main(string[] args)
{
worker w = new worker();
w.salary(5000,6000);
w.salary(10000);
Console.ReadLine();
}
}
}
OUTPUT
8) W.A.P to show multilevel inheritance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace multiinhrit
{
class Area
{
public int l, b;
public void cal_area()
{
Console.WriteLine();
Console.WriteLine("The area is:(l*b) " + (l * b));
}
}
class volume : Area
{
public int h;
public void cal_volume()
{
Console.WriteLine();
Console.WriteLine("The volume is: " + (l * b * h));
}
}
class density : volume
{
int m;
public density(int ll, int bb, int hh, int mm)
{
l = ll;
b = bb;
h = hh;
m = mm;
}
public void cal_density()
{
int d;
d = m / (l * b * h); Console.WriteLine();
Console.WriteLine("The density is: " + d);
}
public void showdata()
{
Console.WriteLine("The length is: " + l);
Console.WriteLine();
Console.WriteLine("The breadth is: " + b);
Console.WriteLine();
Console.WriteLine("The height is: " + h);
Console.WriteLine();
Console.WriteLine("The mass is: " + m);
}
}
class Program
{
static void Main(string[] args)
density dense = new density(12,10,5,4000);
dense.showdata();
dense.cal_volume();
dense.cal_area();
dense.cal_
density();
Console.R
ead();
}
}
}
OUTPUT
9) W.A.P to print star pyramid.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace star
{
class Program
{
static void Main(string[] args)
{
int i,j;
Console.WriteLine("pyramid of star:");
for (i = 0; i <= 5; i++)
{
for (j = 0; j < i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
OUTPUT
WINDOWS PROGRAMMING
10) W.a.P to print the factorial of a given no.
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 fact
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int n,i,fact=1;
n = Convert.ToInt32(textBox1.Text);
for (i = 1; i <= n; i++)
{
fact = fact * i;
}
textBox2.Text = Convert.ToString(fact);
}
OUTPUT
11) W.A.P to find the greatest of three nos.
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 greatest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
c = Convert.ToInt32(textBox3.Text);
if (a > b && a > c)
{
MessageBox.Show("A is Greatest");
}
else
{
if (b > c)
{
MessageBox.Show("B is Gratest");
}
else
{
MessageBox.Show("C is Greatest");
}
}
textBox1.Text
= "";
textBox2.Text
= "";
textBox3.Text
= "";
}
}
}
OUTPUT
12) W.A.P to display calculator.
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 calc
{
public partial class Form1 : Form
{
String str = "";//globally
String str1 = "";
Double i, j, k,flag=0;
public Form1()
{
InitializeComponent();
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = " ";
textBox2.Text = " ";
str = "";
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text =str+ "1";
str = textBox1.Text;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text =str+ "2";
str = textBox1.Text;
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = str+"3";
str = textBox1.Text;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = str+"4";
str = textBox1.Text;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = str+"5";
str = textBox1.Text;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = str+"6";
str = textBox1.Text;
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = str+"7";
str = textBox1.Text;
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = str+"8";
str = textBox1.Text;
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = str+"9";
str = textBox1.Text;
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = str+"0";
str = textBox1.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button11_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
textBox1.Text = "";
str = "";
str1 = "+";
}
private void button15_Click(object sender, EventArgs e)
{
i = Convert.ToDouble(textBox2.Text);
j = Convert.ToDouble(textBox1.Text);
if (str1 == "+")
k = i + j;
if (str1 == "-")
k = i - j;
if (str1 == "*")
k = i * j;
if (str1 == "/")
k = i / j;
if (str1 == "%")
k = i % j;
textBox1.Text = k.ToString();
}
private void button12_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
textBox1.Text = "";
str = "";
str1 = "-";
}
private void button13_Click(object sender, EventArgs e)
textBox2.Text = textBox1.Text;
str = "";
str1 = "*";
}
private void button14_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
textBox1.Text = "";
str = "";
str1 = "/";
}
private void button20_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
textBox1.Text = "";
str = "";
str1 = "%";
}
private void button18_Click(object sender, EventArgs e)
{
this.Close();
}
private void button17_Click(object sender, EventArgs e)
{
if (flag == 0)
{
textBox1.Text = str + ".";
str = textBox1.Text;
flag = 1;
}
else
{ str = textBox1.Text;
}
}
13) W.A.P. for Notepad.
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 notepad
public partial class Form1 : Form
)
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
//Shows the openFileDialog
openFileDialog1.ShowDialog();
//Reads the text file
System.IO.StreamReader OpenFile = new
System.IO.StreamReader(openFileDialog1.FileName);
//Displays the text file in the textBox
txtMain.Text = OpenFile.ReadToEnd();
//Closes the proccess
OpenFile.Close();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
//Determines the text file to save to
System.IO.StreamWriterSaveFile = new
System.IO.StreamWriter(openFileDialog1.FileName);
//Writes the text to the file
SaveFile.WriteLine(txtMain.Text);
//Closes the proccess
SaveFile.Close();
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
//Open the saveFileDialog saveFileDialog1.ShowDialog();
//Determines the text file to save to
System.IO.StreamWriterSaveFile = new
System.IO.StreamWriter(saveFileDialog1.FileName);
//Writes the text to the file
SaveFile.WriteLine(txtMain.Text);
//Closes the process
txtMain.Undo();
}
private void redoToolStripMenuItem_Click(object sender, EventArgs e)
{
txtMain.Undo();
}
private void newToolStripMenuItem_Click(object sender, EventArgs
SaveFile.Close();
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
//Declare prntDoc as a new PrintDocument
printDialog1.ShowDialog();
System.Drawing.Printing.PrintDocument prntDoc =
new
System.Drawing.Printing.PrintDocument();
}
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs
e)
{
printPreviewDialog1.ShowDialog();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
e)
{
txtMain.Clear();
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
txtMain.Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
txtMain.Paste();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
txtMain.SelectAll();
}
}
}
Dotnet 18
Dotnet 18

Dotnet 18

  • 1.
    STAR ACADEMY OFTECHNOLOGY AND MANAGEMENT INDORE COMPUTER SCIENCE & ENGINEERING DOTNET TECNOLOGY(CS-406) LAB MANUAL Submitted By : Name : RANJIT KUMAR NAHAK Session : Jan 2014-Jun 2014 Dept. : CSE, SATM
  • 2.
    1) W.A.P toperform basic arithmetic calculation. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace add { class Program { static void Main(string[] args) { int a, b; Console.WriteLine("Enter first nos."); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second no."); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("add is :{0}", a + b); Console.WriteLine("sub is :{0}",a-b); Console.WriteLine("multiis :{0}",a*b); Console.WriteLine("devi is :{0}",a/b); Console.ReadLine(); } } }
  • 3.
  • 4.
    2) W.A.P tointerchange the value of 2 variables without using third variable. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace swap { class Program { static void Main(string[] args) int a = 6; int b = 7; Console.WriteLine("the numbers before swapping a={0} and b={1}",a,b); a = a + b; b = a - b; a = a - b; Console.WriteLine("the numbers after swapping a={0} and b={1}", a, b); Console.Read(); } } }
  • 5.
  • 6.
    3) W.A.P todisplay array elements & their sum. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace array { class Program { static void Main(string[] args) { int[] num = { 10, 20, 30, 40 }; int n = num.Length; Console.WriteLine("array elements"); for (int i = 0; i < n; i++) { Console.WriteLine(num[i]); } int sum = 0; for (int i = 0; i < n; i++) { sum = sum + num[i]; } Console.WriteLine("sum"+sum); Console.Read(); } } }
  • 7.
  • 8.
    4) W.A.P toinput array elements & sort them. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace arrayip { class Program { static void Main(string[] args) int i, j, temp; int[] ar = new int[5]; Console.WriteLine("Enter the elements of array"); for (i = 0; i < ar.Length; i++) { ar[i] = Convert.ToInt32(Console.ReadLine()); } Console.WriteLine("Sorted array is: "); { for (i = 0; i < ar.Length; i++) { for (j = i + 1; j < ar.Length; j++) { if (ar[i] > ar[j]) { temp = ar[i]; ar[i] = ar[j]; ar[j] = temp; } } } for (i = 0; i < ar.Length; i++) { Console.Write(ar[i]); Console.ReadLine(); } } } }}
  • 9.
  • 10.
    5) W.A.P usingc lass. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace { class Program { class student { String nm, dep, gen; public void setdata() { Console.WriteLine("Eter Name"); nm = Console.ReadLine(); Console.WriteLine("Enter Dept"); dep = Console.ReadLine(); Console.WriteLine("Enter gender"); gen = Console.ReadLine(); } public void putdata() { Console.WriteLine("Name " +nm); Console.WriteLine("DEPT " +dep); Console.WriteLine("Gender " +gen); } } static void Main(string[] args) { student stu = new student(); stu.setdata(); stu.putdata(); Console.ReadLine(); } } }
  • 11.
  • 12.
    6) W.A.P toprint fibonacci series. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace fibonic_series { class Program { static void Main(string[] args) { int a, b, c,n; a=0; b=1; Console.WriteLine("Enter Limit: "); n = Convert.ToInt32(Console.ReadLi ne()); Console.WriteLine( a); Console.WriteLine( b); for(int i=3;i<=n;i++) { c = a + b; a = b; b = c; Console.Writ eLine(c); } Console.ReadLine(); } } }
  • 13.
  • 14.
    7) W.A.P usingfunction overloading. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace funover { class Program { class worker { public void salary(int a, int b) { int total, bonus; Console.Write("Enter first bonus: "); bonus = Convert.ToInt32(Console.ReadLine()); total = bonus + a + b; Console.WriteLine(); Console.WriteLine("Total salary is: "+total); Console.WriteLine(); } public void salary(int a) { int total, bonus; Console.Write("Enter second bonus: "); bonus = Convert.ToInt32(Console.ReadLine()); total = bonus + a; Console.WriteLine(); Console.WriteLine("Total salary is: "+total); } } static void Main(string[] args) { worker w = new worker(); w.salary(5000,6000); w.salary(10000); Console.ReadLine(); } }
  • 15.
  • 16.
    8) W.A.P toshow multilevel inheritance. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace multiinhrit { class Area { public int l, b; public void cal_area() { Console.WriteLine(); Console.WriteLine("The area is:(l*b) " + (l * b)); } } class volume : Area { public int h; public void cal_volume() { Console.WriteLine(); Console.WriteLine("The volume is: " + (l * b * h)); } } class density : volume { int m; public density(int ll, int bb, int hh, int mm) { l = ll; b = bb; h = hh; m = mm; } public void cal_density() { int d; d = m / (l * b * h); Console.WriteLine(); Console.WriteLine("The density is: " + d); }
  • 17.
    public void showdata() { Console.WriteLine("Thelength is: " + l); Console.WriteLine(); Console.WriteLine("The breadth is: " + b); Console.WriteLine(); Console.WriteLine("The height is: " + h); Console.WriteLine(); Console.WriteLine("The mass is: " + m); } } class Program { static void Main(string[] args) density dense = new density(12,10,5,4000); dense.showdata(); dense.cal_volume(); dense.cal_area(); dense.cal_ density(); Console.R ead(); } } }
  • 18.
  • 19.
    9) W.A.P toprint star pyramid. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace star { class Program { static void Main(string[] args) { int i,j; Console.WriteLine("pyramid of star:"); for (i = 0; i <= 5; i++) { for (j = 0; j < i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadLine(); } } }
  • 20.
  • 21.
    10) W.a.P toprint the factorial of a given no. 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 fact { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int n,i,fact=1; n = Convert.ToInt32(textBox1.Text); for (i = 1; i <= n; i++) { fact = fact * i; } textBox2.Text = Convert.ToString(fact); }
  • 22.
  • 23.
    11) W.A.P tofind the greatest of three nos. 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 greatest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int a, b, c; a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); c = Convert.ToInt32(textBox3.Text); if (a > b && a > c) { MessageBox.Show("A is Greatest"); } else { if (b > c) { MessageBox.Show("B is Gratest"); } else { MessageBox.Show("C is Greatest"); } } textBox1.Text
  • 24.
  • 25.
  • 26.
    12) W.A.P todisplay calculator. 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 calc { public partial class Form1 : Form { String str = "";//globally String str1 = ""; Double i, j, k,flag=0; public Form1() { InitializeComponent(); } private void button16_Click(object sender, EventArgs e) { textBox1.Text = " "; textBox2.Text = " "; str = ""; } private void button1_Click(object sender, EventArgs e) { textBox1.Text =str+ "1"; str = textBox1.Text; } private void button2_Click(object sender, EventArgs e) {
  • 27.
    textBox1.Text =str+ "2"; str= textBox1.Text; } private void button3_Click(object sender, EventArgs e) { textBox1.Text = str+"3"; str = textBox1.Text; } private void button4_Click(object sender, EventArgs e) { textBox1.Text = str+"4"; str = textBox1.Text; } private void button5_Click(object sender, EventArgs e) { textBox1.Text = str+"5"; str = textBox1.Text; } private void button6_Click(object sender, EventArgs e) { textBox1.Text = str+"6"; str = textBox1.Text; } private void button7_Click(object sender, EventArgs e) { textBox1.Text = str+"7"; str = textBox1.Text; } private void button8_Click(object sender, EventArgs e) { textBox1.Text = str+"8"; str = textBox1.Text; }
  • 28.
    private void button9_Click(objectsender, EventArgs e) { textBox1.Text = str+"9"; str = textBox1.Text; } private void button10_Click(object sender, EventArgs e) { textBox1.Text = str+"0"; str = textBox1.Text; } private void Form1_Load(object sender, EventArgs e) { } private void button11_Click(object sender, EventArgs e) { textBox2.Text = textBox1.Text; textBox1.Text = ""; str = ""; str1 = "+"; } private void button15_Click(object sender, EventArgs e) { i = Convert.ToDouble(textBox2.Text); j = Convert.ToDouble(textBox1.Text); if (str1 == "+") k = i + j; if (str1 == "-") k = i - j; if (str1 == "*") k = i * j; if (str1 == "/") k = i / j; if (str1 == "%") k = i % j; textBox1.Text = k.ToString(); }
  • 29.
    private void button12_Click(objectsender, EventArgs e) { textBox2.Text = textBox1.Text; textBox1.Text = ""; str = ""; str1 = "-"; } private void button13_Click(object sender, EventArgs e) textBox2.Text = textBox1.Text; str = ""; str1 = "*"; } private void button14_Click(object sender, EventArgs e) { textBox2.Text = textBox1.Text; textBox1.Text = ""; str = ""; str1 = "/"; } private void button20_Click(object sender, EventArgs e) { textBox2.Text = textBox1.Text; textBox1.Text = ""; str = ""; str1 = "%"; } private void button18_Click(object sender, EventArgs e) { this.Close(); } private void button17_Click(object sender, EventArgs e) { if (flag == 0) { textBox1.Text = str + ".";
  • 30.
    str = textBox1.Text; flag= 1; } else { str = textBox1.Text; } }
  • 32.
    13) W.A.P. forNotepad. 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 notepad public partial class Form1 : Form ) { public Form1() { InitializeComponent(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { //Shows the openFileDialog openFileDialog1.ShowDialog(); //Reads the text file System.IO.StreamReader OpenFile = new System.IO.StreamReader(openFileDialog1.FileName); //Displays the text file in the textBox txtMain.Text = OpenFile.ReadToEnd(); //Closes the proccess OpenFile.Close(); } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { //Determines the text file to save to System.IO.StreamWriterSaveFile = new System.IO.StreamWriter(openFileDialog1.FileName);
  • 33.
    //Writes the textto the file SaveFile.WriteLine(txtMain.Text); //Closes the proccess SaveFile.Close(); } private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { //Open the saveFileDialog saveFileDialog1.ShowDialog(); //Determines the text file to save to System.IO.StreamWriterSaveFile = new System.IO.StreamWriter(saveFileDialog1.FileName); //Writes the text to the file SaveFile.WriteLine(txtMain.Text); //Closes the process txtMain.Undo(); } private void redoToolStripMenuItem_Click(object sender, EventArgs e) { txtMain.Undo(); } private void newToolStripMenuItem_Click(object sender, EventArgs SaveFile.Close(); } private void printToolStripMenuItem_Click(object sender, EventArgs e) { //Declare prntDoc as a new PrintDocument printDialog1.ShowDialog(); System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument(); } private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) { printPreviewDialog1.ShowDialog();
  • 34.
    } private void exitToolStripMenuItem_Click(objectsender, EventArgs e) { Application.Exit(); } private void undoToolStripMenuItem_Click(object sender, EventArgs e) { e) { txtMain.Clear(); } private void cutToolStripMenuItem_Click(object sender, EventArgs e) { } private void copyToolStripMenuItem_Click(object sender, EventArgs e) { txtMain.Copy(); } private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { txtMain.Paste(); } private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) { txtMain.SelectAll(); } } }