Click here to Skip to main content
15,891,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,


I have two queries ..
1: i am making a form application,when it starts it alutomatically goes in the background and when i want to open it again i have use many ways but noe one is work as like ,,.
C#
//private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if (e.KeyChar == Keys.Enter)
        //    {
        //        this.Visible = true;
        //    }
        //}
        //public static void Window_KeyDown(object sender, KeyEventArgs e)
        //{
        //    if (e.Control && e.KeyCode == Keys.D1)
        //    {
        //        string response = ShowDialog("Password Required: ", "Password");
        //        if (response.Equals("##########"))
        //        {
        //            Form1 F = new Form1();
        //            F.Show();
        //        }
        //    }
        //}
       
        //protected override bool ProcessCmdKey(ref Message message, Keys keys)
        //{
                         
        //            if (e.Control && e.KeyCode == Keys.D1)
        //            {
        //                string response = ShowDialog("Password Required: ", "Password");
        //                if (response.Equals("######"))
        //                {
        //                    Form1 F = new Form1();
        //                    F.Show();
        //                }
        //            }

        //            return false;
        //    }

        //    return false;
        //}



and when i right a code in program.cs for making a key pair then it also not working
i am using console.readkey();
but this is used only one time in the app.

i want to show the form any how may be console/windows..

perform the key event when form is not in the focus.
Posted
Updated 25-Feb-15 21:56pm
v2

1 solution

The problem is that when a form does not have the focus, keystrokes do't go to it - they go to the form that does have the focus!

Think about it: if you are typing a letter in word, you don't want your keystrokes (or mouse input for that matter) going to your banking application - it could do anything with the money in your account!
Similarly, when you are using your bank, you don;t want your keystrokes going to other applications, because one of them might be "looking" for your login details.

There are ways to do it - they involve global hooks, and are pretty complicated - but it's probably better if you don't "hide" your application at all, but minimize it to the task bar instead. That way the user can switch to it when he wants.
 
Share this answer
 
Comments
Aditya Chauhan 26-Feb-15 4:23am    
ok i accept this ..
but how instant locker work ..
this is work perfectly can you explain.
this is work with a short cut key
ctrl+L focus or without focus how?
OriginalGriff 26-Feb-15 4:35am    
Do you think we wrote it? :laugh:

It's possible it sets a Windows shortcut key combination, or it uses a global hook.
You should be able to find info on each method via Google.
Be aware that shortcut keys (or global hooks) are a PITA for users. They *always* conflict with something in a different application. If you don't really, really, need it, it's probably better not to spend your time doing it - and it'll probably take quite a while to get working well for all your target OSes, with no guarantee that it'll work in future versions.
Aditya Chauhan 26-Feb-15 6:05am    
ok fine Thanks
Aditya Chauhan 2-Mar-15 1:08am    
Dear Original I have done it .
i made a shortcut key for open a form when it is in hidden condition.
:):):):)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900