Pages

Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Wednesday, November 4, 2015

How to Create a Memory Matching Game in C#

This is the code but you have to create new project and redesign the game.The link of the complete game is given you can download the project .

link of the project : https://www.dropbox.com/s/wsnovk1rugn93ld/C%23.rar?dl=0

























using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MatchingGame
{
    public partial class Form1 : Form
    {
        // firstClicked points to the first Label control 
        // that the player clicks, but it will be null 
        // if the player hasn't clicked a label yet.
        Label firstClicked = null;

        // secondClicked points to the second Label control 
        // that the player clicks.
        Label secondClicked = null;
       
        // Use this Random object to choose random icons for the squares.
        Random random = new Random();

        // Each of these letters is an interesting icon
        // in the Webdings font,
        // and each icon appears twice in this list.
        List<string> icons = new List<string>()
        {
            "!", "!", "N", "N", ",", ",", "k", "k",
            "b", "b", "v", "v", "w", "w", "z", "z"
        };

        /// <summary>
        /// Assign each icon from the list of icons to a random square
        /// </summary>
        private void AssignIconsToSquares()
        {
            // The TableLayoutPanel has 16 labels,
            // and the icon list has 16 icons,
            // so an icon is pulled at random from the list
            // and added to each label.
            foreach (Control control in tableLayoutPanel1.Controls)
            {
                Label iconLabel = control as Label;
                if (iconLabel != null)
                {
                    int randomNumber = random.Next(icons.Count);
                    iconLabel.Text = icons[randomNumber];
                    iconLabel.ForeColor = iconLabel.BackColor;
                    icons.RemoveAt(randomNumber);
                }
            }
        }


        public Form1()
        {
            InitializeComponent();
            AssignIconsToSquares();
        }

        /// <summary>
        /// Every label's Click event is handled by this event handler.
        /// </summary>
        /// <param name="sender">The label that was clicked.</param>
        /// <param name="e"></param>
        private void label_Click(object sender, EventArgs e)
        {
            // The timer is only on after two non-matching 
            // icons have been shown to the player, 
            // so ignore any clicks if the timer is running
            if (timer1.Enabled == true)
                return;
           
            Label clickedLabel = sender as Label;

            if (clickedLabel != null)
            {
                // If the clicked label is black, the player clicked
                // an icon that's already been revealed --
                // ignore the click.
                if (clickedLabel.ForeColor == Color.Black)
                    // All done - leave the if statements.
                    return;

                // If firstClicked is null, this is the first icon 
                // in the pair that the player clicked,
                // so set firstClicked to the label that the player 
                // clicked, change its color to black, and return.
                if (firstClicked == null)
                {
                    firstClicked = clickedLabel;
                    firstClicked.ForeColor = Color.Black;

                    // All done - leave the if statements.
                    return;
                }

                // If the player gets this far, the timer isn't
                // running and firstClicked isn't null,
                // so this must be the second icon the player clicked
                // Set its color to black.
                secondClicked = clickedLabel;
                secondClicked.ForeColor = Color.Black;

                // Check to see if the player won.
                CheckForWinner();
               
                // If the player clicked two matching icons, keep them 
                // black and reset firstClicked and secondClicked 
                // so the player can click another icon.
                if (firstClicked.Text == secondClicked.Text)
                {
                    firstClicked = null;
                    secondClicked = null;
                    return;
                }
               
                // If the player gets this far, the player 
                // clicked two different icons, so start the 
                // timer (which will wait three quarters of 
                // a second, and then hide the icons).
                timer1.Start();
            }
        }

        /// <summary>
        /// This timer is started when the player clicks 
        /// two icons that don't match,
        /// so it counts three quarters of a second 
        /// and then turns itself off and hides both icons.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Stop the timer.
            timer1.Stop();

            // Hide both icons.
            firstClicked.ForeColor = firstClicked.BackColor;
            secondClicked.ForeColor = secondClicked.BackColor;

            // Reset firstClicked and secondClicked 
            // so the next time a label is
            // clicked, the program knows it's the first click.
            firstClicked = null;
            secondClicked = null;
        }

        /// <summary>
        /// Check every icon to see if it is matched, by 
        /// comparing its foreground color to its background color. 
        /// If all of the icons are matched, the player wins.
        /// </summary>
        private void CheckForWinner()
        {
            // Go through all of the labels in the TableLayoutPanel, 
            // checking each one to see if its icon is matched.
            foreach (Control control in tableLayoutPanel1.Controls)
            {
                Label iconLabel = control as Label;

                if (iconLabel != null)
                {
                    if (iconLabel.ForeColor == iconLabel.BackColor)
                        return;
                }
            }

            // If the loop didn’t return, it didn't find
            // any unmatched icons.
            // That means the user won. Show a message and close the form.
            MessageBox.Show("You matched all the icons!", "Congratulations!");
            Close();
        }

    }
}


Tuesday, October 13, 2015

Code of How to calculate under root in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int low = 0;
            int n,ans,high = 0;
            Console.Write("Enter the value of n for the underroot : ");
            n=int.Parse(Console.ReadLine());
           // high = n;
            for(int i=0;i<=n;i++)
            {
                low += 1;
                high += 1;
                ans = low * high;
                if(ans==n && low==high)
                {
                    Console.Write("the squareroot is : ");
                    Console.WriteLine(low);
                }
                else
                {
                    continue;
                }
            }
            Console.ReadLine();
            
        }
    }
}

Saturday, June 20, 2015

How to Use Key Event Args in C#


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 _10._1_keyboard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            label1.Text = "Alt " + (e.Alt ? "Yes" : "No") + "\n" + " Shift"
                + (e.Shift ? " Yes" : "No") + " Ctrl " + (e.Control ? " Yes" : " No")
                + "\n" + "Key Code " + e.KeyCode + "\n" + "Key Value "
                + e.KeyValue + "\n" + "Key Data " + e.KeyData + "\n";

           
        }
    }
}



C# Program to Implement Binary Search Tree using Linked List

using System;
using System.Collections.Generic;
using System.Text;
namespace TreeSort
{
    class Node
    {
        public int item;
        public Node leftc;
        public Node rightc;
        public void display()
        {
            Console.Write("[");
            Console.Write(item);
            Console.Write("]");
        }
    }
    class Tree
    {
        public Node root;
        public Tree()
        {
            root = null;
        }
        public Node ReturnRoot()
        {
            return root;
        }
        public void Insert(int id)
        {
            Node newNode = new Node();
            newNode.item = id;
            if (root == null)
                root = newNode;
            else
            {
                Node current = root;
                Node parent;
                while (true)
                {
                    parent = current;
                    if (id < current.item)
                    {
                        current = current.leftc;
                        if (current == null)
                        {
                            parent.leftc = newNode;
                            return;
                        }
                    }
                    else
                    {
                        current = current.rightc;
                        if (current == null)
                        {
                            parent.rightc = newNode;
                            return;
                        } } } }
        }
        public void Preorder(Node Root)
        {
            if (Root != null)
            {
                Console.Write(Root.item + " ");
                Preorder(Root.leftc);
                Preorder(Root.rightc);
            }
        }
        public void Inorder(Node Root)
        {
            if (Root != null)
            {
                Inorder(Root.leftc);
                Console.Write(Root.item + " ");
                Inorder(Root.rightc);
            }
        }
        public void Postorder(Node Root)
        {
            if (Root != null)
            {
                Postorder(Root.leftc);
                Postorder(Root.rightc);
                Console.Write(Root.item + " ");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Tree theTree = new Tree();
            theTree.Insert(20);
            theTree.Insert(25);
            theTree.Insert(45);
            theTree.Insert(15);
            theTree.Insert(67);
            theTree.Insert(43);
            theTree.Insert(80);
            theTree.Insert(33);
            theTree.Insert(67);
            theTree.Insert(99);
            theTree.Insert(91);           
            Console.WriteLine("Inorder Traversal : ");
            theTree.Inorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Preorder Traversal : ");
            theTree.Preorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Postorder Traversal : ");
            theTree.Postorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.ReadLine();
        }
    }

}

Wednesday, June 17, 2015

Statistical Analysis and Histogram


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Statistiacal_Analysis
{
    class data
    {
        //Function  for Mean-----------------------------------------------------------------------------------------
        public int mean(int[] arr, int num)
        {
            int me = 0;
            for (int i = 0; i < num; i++)
            {
                me = me + arr[i];
            }
            me = me / num;
            return me;
        }

        //------------------------------------------------------------------------------------------------------------------
        //Function for Median----------------------------------------------------------------------------------------
        public void median(int[] arr, int num)
        {
            int me = 0;
            // For Even Size Of The Array----------------------------------------------------------------------------
            if (num % 2 == 0)
            {
                me = ((arr[(num / 2) - 1]) + (arr[num / 2])) / 2;

                Console.WriteLine("The Median Is : " + me);
                Console.WriteLine("=======================================================");
            }
            // For Odd  Size Of The Array---------------------------------------------------------------------------
            else
            {
                me = arr[((num + 1) / 2) - 1];

                Console.WriteLine("The Median is : " + me);
                Console.WriteLine("=======================================================");
            }

        }

        //-----------------------------------------------------------------------------------------------------------------
        //Function  for Mode-------------------------------------------------------------------------------------
        public void mode(int[] array, int size)
        {

            int counter = 1;
            int max = 0;
            int Mode = array[0];
            for (int pass = 0; pass < size - 1; pass++)
            {
                if (array[pass] == array[pass + 1])
                {
                    counter++;
                    if (counter > max)
                    {
                        max = counter;
                        Mode = array[pass];
                    }
                }
                else
                    counter = 1; // reset counter.
            }
            Console.WriteLine("The mode is: " + Mode);
            Console.WriteLine("========================================================");
        }

        //------------------------------------------------------------------------------------------------------------------
        //Function for Standerd Deviation--------------------------------------------------------------------------
        public void stanDev(int[] arr, int num)
        {

            double sd = 0.0;
            double power = 2.0;
            double val = 0.0;
            int Mean = mean(arr, num);
            for (int i = 0; i < num; i++)
            {
                val = (arr[i] - Mean);
                sd = sd + (Math.Pow(val, power)) / (num - 1);
            }

            Console.WriteLine("The Standerd Deviation Is : " + (Math.Sqrt(sd)));
            Console.WriteLine("=======================================================");
        }
        //-----------------------------------------------------------------------------------------------------------------
        //Function For Printing Histogram---------------------------------------------------------------------------
        public void histogram(int[] arr, int num)
        {
            string[][] a = new string[num][];
            for (int i = 0; i < num; i++)
            {
                a[i] = new string[arr[i]];
            }
            Console.Write("Element\t\tValue\t\tHistogram\n");
            Console.WriteLine();
            for (int i = 0; i < num; i++)
            {
                Console.Write(i + "\t\t" + arr[i] + "\t\t");
                for (int j = 0; j < arr[i]; j++)
                {
                    if (j % 4 == 0 && j != 0)
                    {
                        a[i][j] += "|";
                    }
                    else
                    {
                        a[i][j] += "*";
                    }
                   
                    Console.Write(a[i][j]);
                }
                Console.WriteLine();
            }
        }
        //-----------------------------------------------------------------------------------------------------------------
    }
}
//------------------------------------------------- Class data ends here---------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Statistiacal_Analysis
    class Program
    {
        //DRIVER METHOD--------------------------------------------------------------------------------------
        static void Main(string[] args)
        {
            data z = new data();
            string s="";
            // Declarations Of  Variables -----------------------------------------------------------------------
            Random r = new Random();
            int a=0;
            // Dynamically Generated Size In  Array-------------------------------------------------------------
            Console.WriteLine("=======================================================");
            Console.WriteLine("\t\t\t      STAISTICAL DATA ANALYSIS");
            Console.WriteLine("=======================================================");
            Console.Write("Enter The Size OF The Array : ");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("-------------------------------------------------------------------------------");
            int []N=new int[a];

            // Random Numbers Assigned To The Array-----------------------------------------------------------
            for (int i = 0; i < a; i++)
            {
                N[i] = r.Next(0, 9);
                
                Console.WriteLine("The Collected Sample # "+ i +" Is : " + N[i]);                
            }
            Console.WriteLine("=======================================================");
            for (int i = 0; i < a; i++)
            {
                //Sorting The Array In Order To Calculate Mode---------------------------------------------------
                Array.Sort(N);

                //Printing The Sorted Array----------------------------------------------------------------------------
                Console.WriteLine("The Sorted Data Is : " + N[i]);               
            }
          
            //---------------------------------------------------------------------------------------------------------------

            //function call for Mean------------------------------------------------------------------------------------
            Console.WriteLine("=======================================================");
            Console.WriteLine("The Mean Is : "+z.mean(N,a));
            Console.WriteLine("=====================================================");
            //---------------------------------------------------------------------------------------------------------------

            //function call for Median----------------------------------------------------------------------------------
            z.median(N,a);            
            //--------------------------------------------------------------------------------------------------------------
            //function call for Mode------------------------------------------------------------------------------------
            z.mode(N, a);
            //--------------------------------------------------------------------------------------------------------------
            //function call for Standerd Deviation-------------------------------------------------------------------           
            z. stanDev(N, a);            
            //---------------------------------------------------------------------------------------------------------------

            //function call for Histogram-------------------------------------------------------------------------------
            Console.Write("FOR HISTOGRAM PRESS H OR TO CLOSE PRESS ENTER :  ");
            s=Console.ReadLine();
            if (s == "h")
            {
                z.histogram(N, a);
            }
            else
            {
                Environment.Exit(0);
            }

            Console.ReadLine();
            
        }
    }
}

Monday, June 15, 2015

A C# Program To Explain Get Set Accessor


using System;

namespace Example2
{
  class input
   {
     private static int num1, num2, result;
     public void add()
      {
        result = num1 + num2;
        Console.WriteLine("\n\nAdd = {0}", result);
        Console.ReadLine();
      }

     // Creating property for storing value in num1
     public int Number1
      {
        get
         {
           return num1;
         }
        set
         {
           num1 = value;
         }
      }

     // Creating property for storing value in num2
     public int Number2
      {
        get
         {
           return num2;
         }
        set
         {
           num2 = value;
         }
      }
   }

  class Program
   {
     static void Main(string[] args)
      {
        input inp = new input();
        Console.Write("Enter number 1st:\t");
        inp.Number1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter number 2nd:\t");
        inp.Number2 = Convert.ToInt32(Console.ReadLine());

        inp.add();
      }
   }
}

Saturday, June 13, 2015

Write a program to demonstrate private access specifier?


using System;

namespace Example1
{
  class Program
   {
     private void add()
      {
        int num1, num2, result;
        Console.Write("Enter a number:\t");
        num1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("\nEnter second number:\t");
        num2 = Convert.ToInt32(Console.ReadLine());

        result = num1 + num2;
        Console.WriteLine("{0} + {1} = {2}", num1, num2,           result);
      }
     static void Main(string[] args)
      {
        Program p = new Program();
        p.add(); //It is valid, because private add() is           in same class
        Console.ReadLine();
      }
   }
}

Friday, June 12, 2015

Example of Multi Dimension Array

using System;

namespace multi_dimensional_array
{
  class Program
   {
     static void Main(string[] args)
      {
        int i, j;
        //Declaring multi dimensional array
        string[,] Books = new string[3,3];
        for (i = 0; i < 3; i++)
         {
           for (j = 0; j < 3; j++)
            {
              Console.Write("\nEnter Book Name for {0}.                   Row and {1}. column:\t",i+1,j+1);
              Books[i,j] = Console.ReadLine();
            }
         }

        Console.WriteLine("\n\n=========================");
        Console.WriteLine("All the element of Books array            is:\n\n");

        //Formatting Output
        Console.Write("\t1\t2\t3\n\n");
        //outer loop for accessing rows
        for (i = 0; i < 3; i++)
         {
           Console.Write("{0}.\t", i + 1);

           //inner or nested loop for accessing column                of each row
           for (j = 0; j < 3; j++)
            {
              Console.Write("{0}\t", Books[i,j]);
            }
           Console.Write("\n");
         }
        Console.WriteLine("\n\n=========================");
        Console.ReadLine();
      }
   }
}

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;              
            }       
        }       
    }

}