This is a migrated thread and some comments may be shown as answers.

Hiding The Menu Bar

6 Answers 100 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Alan Bound
Top achievements
Rank 1
Alan Bound asked on 07 Aug 2009, 09:57 PM
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.

6 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 13 Aug 2009, 10:35 AM
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.
0
Alan Bound
Top achievements
Rank 1
answered on 17 Aug 2009, 10:03 PM
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).
0
Victor
Telerik team
answered on 18 Aug 2009, 11:30 AM
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.
0
Alan Bound
Top achievements
Rank 1
answered on 19 Aug 2009, 10:41 PM
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;

 

            }

        }

    }

0
Alan Bound
Top achievements
Rank 1
answered on 19 Aug 2009, 10:42 PM
ps: sorry for the horrible way the answer formatted itself, it looked good in the reply window.
0
Victor
Telerik team
answered on 20 Aug 2009, 07:58 AM
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.
Tags
Menu
Asked by
Alan Bound
Top achievements
Rank 1
Answers by
Victor
Telerik team
Alan Bound
Top achievements
Rank 1
Share this question
or