Maybe I should be doing this differently... but in case I have the right idea, how do I go about doing it?

I have the following code:

void eventKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Control && e.KeyCode == Keys.O)
                this.eventOpenFile();
        }

        private void eventOpenFile(object sender, EventArgs e)
        {
            openFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            DialogResult result = openFile.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
                string file = openFile.FileName;
                try
                {
                    string text = File.ReadAllText(file);
                    textBox1.Text = text;
                }
                catch (IOException)
                {
                }
                Console.WriteLine(result); // <-- For debugging use only.
            }
        }

I want ctrl-o to open the "Open File" dialog box. I already have an event setup to work when the UI is clicked. How do I trigger the same event from my eventKeyDown() event handler? What you see there on line 4 clearly doesn't work...

Nevermind - I just made a separate method to open the dialog box, and had the two separate event handlers call that method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.