当表单隐藏/没有焦点时,如何在c#中显示窗口表单/对话框。 [英] how can show a window form/dialog box in c# when form is hide/without focus.

查看:74
本文介绍了当表单隐藏/没有焦点时,如何在c#中显示窗口表单/对话框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,





我有两个疑问..

1:我正在制作一个表单应用程序,当它启动时它会自动进入后台,当我想再次打开它时我会使用很多方法但是没有一个像是一样工作。

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 ,,.

//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;
        //}







当我在program.cs中修改代码来制作密钥对时,它也无法工作

i我正在使用控制台。 readkey();

但这只在应用程序中使用过一次。



i想要显示表单任何怎么可能是console /窗口..



当窗体不在焦点时执行键事件。




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.

推荐答案

问题就是当一个表单没有焦点时,键击不会去 - 它们会转到 具有焦点的形式!



想一想:如果你在输入一封信也就是说,你不希望你的键盘(或鼠标输入)进入你的银行应用程序 - 它可以用你帐户中的钱做任何事情!

同样,当你使用你的银行时,你不希望你的键盘转到其他应用程序,因为其中一个可能查找你的登录详细信息。



有办法做到这一点 - 它们涉及全局钩子,并且非常复杂 - 但如果你根本不隐藏你的应用程序,可能会更好,但最好将它最小化到任务栏。这样用户可以在他想要的时候切换到它。
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.


这篇关于当表单隐藏/没有焦点时,如何在c#中显示窗口表单/对话框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆