Hiding The Menu Bar

7 posts, 0 answers
  1. Alan Bound
    Alan Bound avatar
    4 posts
    Member since:
    Jun 2009

    Posted 07 Aug 2009 Link to this post

    I'm looking for a way to toggle hide and unhide for the menu bar on an application. I want it to toggle when the user presses 'Alt' just like on Internet Explorer 8.
    All attempts I have made so far have failed. Capturing KeyDown has a tendancy to make the toggling flicker if the Alt key is pressed too long. Also, the menu toggles if the user trys ALT+Tab or any other Alt key function.
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 13 Aug 2009 Link to this post

    Hi Alan Bound,

    Thank you for writing. You should be toggling the menu on key up, not on key down, if you do it on key up, alt + tab/any key will work. Please not that the menu in internet explorer displays/hides on key up. Write again if you have other questions.

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alan Bound
    Alan Bound avatar
    4 posts
    Member since:
    Jun 2009

    Posted 17 Aug 2009 Link to this post

    Tried your suggestion, but still had a few problems.
    I am attempting to capture the Alt key, to (un)hide the menu. But I'm not able to capture key up on the Alt key (though I can on other keys).
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 18 Aug 2009 Link to this post

    Hello Alan Bound,

    Thank you for writing. Please send sample code to illustrate exactly what you are doing. I am interested in the way you are listening for incoming key presses. Your menu must be able to process keyboard input which is not directed to it. In order to implement the menu hiding/showing on the alt key, you must implement a message filter somewhere. I am looking forward to your reply.

    Greetings,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Alan Bound
    Alan Bound avatar
    4 posts
    Member since:
    Jun 2009

    Posted 19 Aug 2009 Link to this post

    Here is code I have been writing in an attempt to learn more and find a way around my problem. This is not what I actually want to do, but does hi-lite my problems. In the example I am attempting to capture Ctrl-Alt-Y or Alt-[Anything but Y], in my real application I want to capture Alt alone.

    In the example Ctrl-Alt-Y works just fine, but Alt-G (for example) reaches the line I have tagged with "  //** HERE ** " and (int)Control.ModifierKeys is null. When pressing just Alt, (m.Msg == WM_KEYUP) is never true.

    In the form constructer I have:
        

     

        Application.AddMessageFilter(new MessageFilter(this));

    Plus I have this class:

     

        public

     

    class MessageFilter : IMessageFilter

     

     

     

     

        {

     

            private Form FOwner; //instance of the form in which you want to handle this pre-processing

     

     

     

     

     

            const int WM_KEYUP = 0x101;

     

     

            public MessageFilter(Form aOwner)

     

            {

                FOwner = aOwner;

            }

     

            
            public
    bool PreFilterMessage(ref Message m)

     

            {

     

                bool ret = true;

     

     

                if (m.Msg == WM_KEYUP)

     

                {

     

                    Keys key = (Keys)(int)m.WParam & Keys.KeyCode;

     

     

                    // example code which does work

     

     

     

     

     

                    if (key == Keys.Y)

     

                    {

     

                        if ((int)Control.ModifierKeys == ((int)Keys.Control | (int)Keys.Alt))

     

                        {

     

                            MessageBox.Show("Captured Ctrl-Alt-Y");

     

                        }

     

                        else

     

     

     

     

                        {

                            ret =

    false;

     

                        }

                    }

     

                    else

     

     

     

     

     

                    // example code which does not work

     

     

     

     

                    {

     

                        if ((int)Control.ModifierKeys == ((int)Keys.Alt))   //** HERE **
                        {

     

     

                            MessageBox.Show("Captured Alt");

     

                        }

                    }

     

                    return ret;

     

                }

     

                else

     

     

     

     

                {

     

                    return false;

     

                }

            }

        }

  7. Alan Bound
    Alan Bound avatar
    4 posts
    Member since:
    Jun 2009

    Posted 19 Aug 2009 Link to this post

    ps: sorry for the horrible way the answer formatted itself, it looked good in the reply window.
  8. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 20 Aug 2009 Link to this post

    Hello Alan Bound,

    Thank you for the code. The issue is that you have to handle SYSKEYUP and SYSKEYDOWN notifications in order to properly handle the alt press (and the F10 key if you need to). You can use a boolean value to determine if the alt key is being held down. Also in this article you can see than you can look at the 30th bit of the lParam in order to determine whether the key is pressed for the first time (you can use that to avoid constant repetition of code due to the SYSKEYDOWN repeatedly firing). I am suggesting this approach because we are using it in RadMenu and it works really nice.

    You can use the file button with the two angle brackets in order to paste code from visual studio. It is positioned second from right to left on the support ticket editor. Write again if you need further assistance.

    All the best,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for WinForms is Visual Studio 2017 Ready