Aim:

To perform the c#  Wordpad application in c# windows form.

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 Wordpad application.

Step3: Type a code for new menu button.
richTextBox1.Clear();

Step 4: Type a code for open menu button.
openFileDialog1.ShowDialog();
System.IO.StreamReaderofd = newSystem.IO.StreamReader(openFileDialog1.FileName);
richTextBox1.Text = ofd.ReadToEnd();
ofd.Close();

Step5: Type a code for save menu button.
if (string.IsNullOrEmpty(Path))
using (SaveFileDialogsfd = newSaveFileDialog() { Filter = "TextDocument|*.txt", ValidateNames = true })
if (sfd.ShowDialog() == DialogResult.OK)
using (System.IO.StreamWritersw = newSystem.IO.StreamWriter(sfd.FileName))
sw.WriteLine(richTextBox1.Text);

Step 6:Type a code for Exit button
Application.Exit();

Step 7: 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;

namespace WindowsFormsApplication1
{

publicpartialclassForm1 : Form
    {
String Path;
public Form1()
        {
InitializeComponent();
        }


privatevoidcopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
richTextBox1.Copy();
        }

privatevoidpasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
richTextBox1.Paste();
        }

privatevoidcutToolStripMenuItem_Click(object sender, EventArgs e)
        {
richTextBox1.Cut();
        }

privatevoidselectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
richTextBox1.SelectAll();
        }

privatevoid newToolStripMenuItem1_Click(object sender, EventArgs e)
        {
richTextBox1.Clear();
        }

privatevoidopenToolStripMenuItem_Click(object sender, EventArgs e)
        {
openFileDialog1.ShowDialog();
System.IO.StreamReaderofd = newSystem.IO.StreamReader(openFileDialog1.FileName);
            richTextBox1.Text = ofd.ReadToEnd();
ofd.Close();
        }

privatevoidsaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
if (string.IsNullOrEmpty(Path))
            {
using (SaveFileDialogsfd = newSaveFileDialog() { Filter = "TextDocument|*.txt", ValidateNames = true })
                {
if (sfd.ShowDialog() == DialogResult.OK)
                    {
using (System.IO.StreamWritersw = newSystem.IO.StreamWriter(sfd.FileName))
                        {
sw.WriteLine(richTextBox1.Text);
                        }
                    }
                }
            }
        }

privatevoidexitToolStripMenuItem_Click(object sender, EventArgs e)
        {
Application.Exit();
        }
        }
    }

OUTPUT




BY
      REGU RAM SV.

Post a Comment

أحدث أقدم