Hello, I design a form that use keydown event such as F1, F2, F3 and so on. The form have access right according to the user logging in. If user is an admin then the user will have the right to access all the form. However, if the user is a normal user then the user will only have access to certain form only. For example, to open Form1, user can press button F1 to open the form. How can i disable it if user don't have the right to access the form?

Thank you.

Hi.
In the form's KeyDown event ,we has an object e as type System.Window.Form.KeyEventArgs.We could use this object to check what key is pressed,so doing correlative work.

private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
             switch (e.KeyCode)
            {
                case Keys.F1: //do admin work here
                    break;
                case Keys.F2: // do normal user work here
                    break;
                //.........
            }
        }

Have a nice day.

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.