Pages

Thursday, June 11, 2015

Word Processor



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;
using System.Drawing.Printing;

using System.IO;
namespace Word_Processer
{
    public partial class WordPadForm : Form
    {
        public WordPadForm()
        {
            InitializeComponent();
        }

        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Clear();       //Clears the WordNote(RichTextBox)
        }
       
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog opd = new OpenFileDialog();
            opd.DefaultExt = "rtf";
            opd.ShowHelp = true;
            DialogResult result = opd.ShowDialog();
            if (result == DialogResult.OK)
            {
                string filename = opd.FileName;
                //Open File Dialog Can Be Used To Open A File But With RTF Extension
                WordNote.LoadFile(filename);
            }
        }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            //Save File Dialog Can Be Used To Save A File But With RTF Extension
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = "rtf";
            sfd.ShowHelp = true;
            DialogResult res = sfd.ShowDialog();
            if (res == DialogResult.OK)
            {
                string filename = sfd.FileName;
                WordNote.SaveFile(filename);
            }
        }

        private void printToolStripButton_Click(object sender, EventArgs e)
        {
            PrintDocument docToPrint = new PrintDocument();//Print Document Object  //-> Thanks To MSDN
            PrintDialog pd = new PrintDialog(); //Print Dialog Object   //-> Thanks To MSDN
            //Properties Of Print Dialog Are Initially False, Changed To True So That They Can Be Used
            pd.AllowSomePages = true;
            pd.AllowPrintToFile = true;
            pd.AllowSelection = true;
            pd.AllowCurrentPage = true;
            pd.ShowHelp = true;
            pd.Document = docToPrint;
            DialogResult result = pd.ShowDialog();

            if (result == DialogResult.OK)
            {
                docToPrint.Print();
            }
        }
        private void helpToolStripButton_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.mswordhelp.com/"); 
            // Help Website Will Open In The Default Browser         
        }
        private void Bold_Click(object sender, EventArgs e)
        {
            Font font=WordNote.SelectionFont;//Sets The Selected Font To The Font Variable
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style ^ FontStyle.Bold);
        }
        private void Italic_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style ^ FontStyle.Italic);
        }
        private void UnderLine_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size,font.Style^ FontStyle.Underline);
        }

        private void StrikeOut_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size,font.Style ^ FontStyle.Strikeout);            
        }
        private void Regular_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, FontStyle.Regular);
        }
        private void Center_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Center;
        }
        private void RightAlign_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Right;
        }
        private void LeftAlign_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Left;
        }
        private void Color_Click(object sender, EventArgs e)
        {
            //Color Dialog Is Used Here To Change The Font Color
            ColorDialog cd = new ColorDialog();//Object Of Color Dialog
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            cd.Color = WordNote.ForeColor;
            DialogResult result = cd.ShowDialog();
            if (result == DialogResult.OK)
            {
                WordNote.ForeColor = cd.Color;
                //Color Button's BackColor Is Set With The Fore Color Of The RichTextBox (WordNote)
                Color.BackColor = WordNote.ForeColor;
            }        
        }
        private void Fontsize_SelectedIndexChanged(object sender, EventArgs e)
        {
           //Fontsize ComboBox Is Used Here to Select The Desired Font Size
            string value = Fontsize.SelectedItem.ToString();
            float size = Single.Parse(value);
            WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, size, WordNote.Font.Style);
        }
        private void Fontfamily_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Fontfamily ComboBox Is Used Here to Select The Desired Font Family
            string value = Fontfamily.SelectedItem.ToString();
            WordNote.SelectionFont = new Font(value,WordNote.Font.Size, WordNote.Font.Style);          
        }
        private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //PageSetupDialog Is Used Here To Change The Page Settings
            //->Thanks To MSDN
            PageSetupDialog a = new PageSetupDialog();
            a.PageSettings =   new PageSettings();
            a.PrinterSettings =   new PrinterSettings();
 a.MinMargins = new Margins();a.AllowMargins = true;  a.AllowOrientation = true;
 a.AllowPaper = true;a.AllowPrinter = true;a.ShowNetwork = true;  a.ShowHelp = true;
            a.ShowDialog();          
        }
        private void fontSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Font Dialog For The Format Menu
            FontDialog a = new FontDialog();
            a.ShowHelp = true;
            a.ShowApply = true;
            DialogResult result = a.ShowDialog();
            if (result == DialogResult.OK)
            {
                Font font = a.Font;
             WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style);
            }
        }     
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Open Dialog For the Tool Strip as a Menu Item
            OpenFileDialog opd = new OpenFileDialog();
            opd.DefaultExt = "rtf";
            opd.ShowHelp = true;
            DialogResult result = opd.ShowDialog();
            if (result == DialogResult.OK)
            {
                string filename = opd.FileName;
                //Open File Dialog Can Be Used To Open A File But With RTF Extension
                WordNote.LoadFile(filename);
            }        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Save File Dialog For the Tool Strip as a Menu Item
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = "rtf";
            sfd.ShowHelp = true;
            DialogResult res = sfd.ShowDialog();
            if (res == DialogResult.OK)
            {
                string filename = sfd.FileName;
                //Save File Dialog Can Be Used To Save A File But With RTF Extension
                WordNote.SaveFile(filename);
            }        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrintDocument docToPrint = new PrintDocument();
            //Print Document Object  //-> Thanks To MSDN
            PrintDialog pd = new PrintDialog(); //Print Dialog Object   --> Thanks To MSDN
            //Properties Of Print Dialog Are Initially False, Changed To True So That They Can Be Used                
pd.AllowSomePages = true;pd.AllowPrintToFile = true;  pd.AllowSelection = true;
     pd.AllowCurrentPage = true;            pd.ShowHelp = true;
     pd.Document = docToPrint;   DialogResult result = pd.ShowDialog();

            if (result == DialogResult.OK)
            {
                docToPrint.Print();
            }        }
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();     //To Close The Application
        } 
        private void BulletindentButton_Click(object sender, EventArgs e)
        {
            //Bullet Toggle Button
            if (WordNote.SelectionBullet == false)
            {
                WordNote.SelectionBullet = true;
       WordNote.BulletIndent = 20;  //Indent Is The Space Between The Bullet and The Text          
            }
            else
            {
                WordNote.SelectionBullet = false;
            }        }

        private void DecreasefontSizeButton_Click(object sender, EventArgs e)
        {
            //Font Size Decrease Using The Selected Index
            if (Fontsize.SelectedIndex != -1)
            {
                int a = Fontsize.SelectedIndex--;
                float f = Single.Parse(a.ToString());
                WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, f, WordNote.Font.Style);
            }
            else if(Fontsize.SelectedIndex ==-1)
            {               
               MessageBox.Show("Font Size Connot Be Less than 9", "Font Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void IncreasefontSizeButton_Click(object sender, EventArgs e)
        {
            //Font Size Increase Using The Selected Index
            if (Fontsize.SelectedIndex<33)
            {
                int a = Fontsize.SelectedIndex++;
                float f = Single.Parse(a.ToString());
                WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, f, WordNote.Font.Style);
            }
            else if (Fontsize.SelectedIndex>32)
            {
                MessageBox.Show("Font Size Connot Be Greater Than 42", "Font Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //The Help Website Will Open In The Default Browser
            System.Diagnostics.Process.Start("http://www.mswordhelp.com/");
        } 
        private void ClearPageButton_Click(object sender, EventArgs e)
        {
            WordNote.Clear();   //To Clear The Page(RichTextBox)                
        }


        private void cutToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Cut();//RichTextBox Built in Function for Cut Operation
        }

        private void copyToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Copy();//RichTextBox Built in Function for Copy Operation
        }

        private void pasteToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Paste();//RichTextBox Built in Function for Paste Operation
        }

        private void paintToolStripMenuItem_Click(object sender, EventArgs e)
        {
           System.Diagnostics.Process.Start("mspaint");//To Start The .exe file Of Paint
        }
        private void symbolsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("charmap");//To Start The .exe file Of Character Map           
        }
        private void FindButton_Click(object sender, EventArgs e)
        {
            WordNote.Find(FindTextBox.ToString());//Built in Function To Find The Desired Word           
        }
        private void UndoButton_Click(object sender, EventArgs e)
        {
            WordNote.Undo();    //Built in Function To Undo The Work           
        }
        private void designToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Color Dialog Is Used Here To Change The BackGround Color Of The RichTextBox
            ColorDialog cd = new ColorDialog();//Object of The ColorDialog
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            cd.Color = WordNote.ForeColor;
            DialogResult result = cd.ShowDialog();
            if (result == DialogResult.OK)
            {
                WordNote.BackColor = cd.Color;              
            }       
        }       
    }

}

No comments:

Post a Comment