954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add a short cut in a Windows Form Application

I making a small office word like program. I have four things. A menu bar containing File>Open,Save,Exit. I want to create a short cut for open, save. Could someone help me how to do that. this is my code

namespace Texteditor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            DialogResult result = saveFile.ShowDialog();

            if (result == DialogResult.Cancel)
                return;

            string strFilename = saveFile.FileName;
            System.IO.StreamWriter sw = System.IO.File.CreateText(strFilename);
            sw.Write(textBox1.Text);
            sw.Close();
 
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileChooser = new OpenFileDialog();
            DialogResult result = fileChooser.ShowDialog();

            if (result == DialogResult.Cancel)
                return;

            string strFilename = fileChooser.FileName;
             
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }
vishal1949
Light Poster
42 posts since Jul 2011
Reputation Points: 21
Solved Threads: 1
 

Could someone also help me with opening a file. This is all i need. my Code is

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileChooser = new OpenFileDialog();
            DialogResult result = fileChooser.ShowDialog();

            if (result == DialogResult.Cancel)
                return;

            string strFilename = fileChooser.FileName;
            StreamReader reader = File.OpenText(strFilename);
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            DialogResult result = saveFile.ShowDialog();

            if (result == DialogResult.Cancel)
                return;

            string strFilename = saveFile.FileName;
            System.IO.StreamWriter sw = System.IO.File.CreateText(strFilename);
            sw.Write(word.Text);
            sw.Close();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
vishal1949
Light Poster
42 posts since Jul 2011
Reputation Points: 21
Solved Threads: 1
 

The ToolStripMenuItem class has a ShortcutKeys property.
Just set this to what you need.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: