Aim:
To perform the C# Notepad application with sum menu operations.Algorithm:
Step 1: Open the visual studio 2010 and select the file menu =>newproject =>windows c# =>windows form applications =>file name =>ok.Step2: Design the form as per the Notepad application.
Step3: Type the code for approximate menu button
Step 4: Add the menu Strip into the form
Step5: Type a code for new menu button.
String path;
Path=string.Empty();
Textbox.clear();
Step 6: Type a code for new open menu.
using (OpenFileDialog.ofd = new OPenFileDialog()
{ Filter = "TextDocuments|*.txt", ValidateNames = true,multiselect=false })
Step 7: Type a code for new open menu.
using (SaveFileDialogsfd = new SaveFileDialog()
{ Filter = "TextDocuments|*.txt", ValidateNames = true })
Step 8:Type a code for exit menu.
Application.Exit();
Step 9: Compile and run the program without error.
PROGRAM
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string path;
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
path = string.Empty;
textBox1.Clear();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(path))
{
using (SaveFileDialogsfd = new SaveFileDialog() { Filter = "TextDocuments|*.txt",
ValidateNames = true })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
using (StreamWritersw = new StreamWriter(sfd.FileName))
{
sw.WriteLine(textBox1.Text);
}
}
}
}
}
private void oPenToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
System.IO.StreamReaderOpenFile = new
System.IO.StreamReader(openFileDialog1.FileName);
textBox1.Text = OpenFile.ReadToEnd();
OpenFile.Close();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void COMPANYToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 ab = new Form3();
ab.Show();
}
}
}
}
BY
REGU RAM SV
Post a Comment