Ctrl + Enter with a MenuStrip

Hi,

I was following a tutorial to try to make my own browser interface.
I tried to implement the Ctrl+Enter in a Textbox to make like Internet Explorer to complete the address, eg.  google => http://www.google.com .
The problem is that I cannot take the Ctrl+Enter keys event while I enable my MenuStrip (eg. File, Options, Help,....) as it makes the focus on the MenuStrip!
When I "un-enable" or delete my MenuStrip, it works well. When try to replace the Control key by the Alt key, it works well too.
There are no shortcuts keys in the MenuStrip.
I tried with the e.Control and e.KeyValue = 17  items, but it stills makes the focus on the MenuStrip.

Is this a bug If it is, is there any workaround Or if I am really bad, can someone help me, please


Answer this question

Ctrl + Enter with a MenuStrip

  • Soc32183

    Hi,

    Isn't that some C code you made Well, I am using Visual Basic 2005...
    Unfortunatly, putting this code at the right place in VB produces lots of errors.

    As I was not able to find an idea to explain to you what was my problem, I thaught that I could show you with screenchot pictures.

    As I cannot upload any file in this community, I put a link that will show you what happens.
    Forgive me if my software is in french (because I am french lol), but all is easier with pictures :) ... and the project itself!

    Here is the picture at this link : ---deleted---
    And the entire project here : ---deleted---

    I checked those links.
    I hope it will really help you this time. And thank you very much for your help.
    Pascal.

  • Wayne Larimore

    Sorry I dont understand what you're asking - the answer depends on what you're doing, we need a few more details:

    1. Is the TextBox within the MenuStrip (e.g. a ToolStripTextBox) or is it a standalone TextBox on the form.

    2. Are you using any special properties/events on the TextBox, e.g. AutoCompleteSource, AutoCompleteMode.

    3. What do you mean by "enable my MenuStrip"


  • AJTessin

    It was C#, here's the VB version



    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AddHandler Me.ToolStripTextBox1.Control.PreviewKeyDown, AddressOf ToolStripTextBox_PreviewKeyDown
            AddHandler Me.ToolStripTextBox1.KeyDown, AddressOf ToolStripTextBox_KeyDown
        End Sub

        Private Sub ToolStripTextBox_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs)
            If e.KeyData = (Keys.Enter Or Keys.Control) Then
                e.IsInputKey = True
            End If

        End Sub
        Private Sub ToolStripTextBox_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
            If e.KeyData = (Keys.Enter Or Keys.Control) Then
                e.Handled = True
                MessageBox.Show("Do your custom processing here")
            End If

        End Sub

    End Class

     


  • ErfangC

    Hmm, I dont get the behavior you're suggesting with the following steps:

    Create a New Windows Forms Project using Visual Studio 2005 (RTM)
    Drop on a MenuStrip
    Select the "Insert Standard Items" command off the Designer Action Panel
    Select arrow on the "Type Here" node, add a ToolStripTextBox
    Set the ToolStripTextBox.AutoCompleteMode to SuggestAppend
    Set the ToolStripTextBox.AutoCompleteSource to AllUrl
    Start debugging the application (F5)

    Type in www.google.com, hit Control+Enter

    Result
    I see focus is still in the text box, the MenuStrip not "activated".

    From this project I can intercept control + enter using the following code:

     


      public Form1() {
                InitializeComponent();
                toolStripTextBox1.TextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(TextBox_PreviewKeyDown);
                toolStripTextBox1.KeyDown += new KeyEventHandler(toolStripTextBox1_KeyDown);
            }

            void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) {
                if (e.KeyData == (Keys.Enter | Keys.Control)) {
                    e.Handled = true;
                    MessageBox.Show("Do your custom processing here");
                }
            }

            void TextBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
                if (e.KeyData == (Keys.Enter | Keys.Control)) {
                    e.IsInputKey = true;
                }
            }


     



    Hope this helps -

    Thanks,
    Jessica


  • richee

    Hi,

    Thank you for answering.
    Here are the answers to your questions:
    1. The TextBox is within the MenuStrip. So, yes it is a ToolStripTextBox.
    2. Yes, I use an AutoCompleteSource and a AutoCompleteMode (AllURL), but I tried without these AutoComplete settings, the problem was still there.
    3. I mean, by "enable my MenuStrip", it activate the Menu like if you were pressing the Alt key to get the focus to the menu. For example, if you don't have a mouse (or even if you have one), you press the Alt and F keys to get the File menu in Word, (and theb you press the DOWN key to get the list and then have New / Open / Save etc...  I hope this example helps.

    I hope I have well answered to your questions, so you will be able to help me.

  • Sinu Ramachandran

    Thank you very much for your help.
    I only just thought that it was easier...

    Thanks again!

  • Ctrl + Enter with a MenuStrip