简体   繁体   English

有没有一种方法可以禁止在Winforms(c#)之外单击,直到用户按下关闭按钮?

[英]Is there a way to disallow clicking outside of winforms (c#) until user presses close button?

I'm currently building a winforms application. 我目前正在构建Winforms应用程序。 The idea is to force the user to press Close or Cancel button and will not remove focus from the winform or be overlapped by the (whatsoever clicked item/apps/) if the user clicks outside of its winform border/size. 这个想法是要迫使用户按下“关闭”或“取消”按钮,并且如果用户在其Winform边框/大小之外单击,则不会将焦点从winform移开或被(无论单击的项目/ apps /什么)重叠。

* Update * *更新*

I am not trying to create a ransomware. 我不是要创建勒索软件。 We are trying to copy the behavior of bootstrap modal that we created in our web app that the only way to close the modal is by pressing our "x" button. 我们正在尝试复制在Web应用程序中创建的引导程序模态的行为,即关闭模态的唯一方法是按下“ x”按钮。 We are focusing on consistency. 我们专注于一致性。

I hope that you are talking about a modal dialog - one that blocks interaction with the rest of your application, rather than all applications running on the PC. 我希望您正在谈论的是一种模式对话框 -一种阻止与应用程序其余部分(而不是与PC上运行的所有应用程序)交互的对话框

Assuming this is the case, do the following when opening your dialog: 假设是这种情况,请在打开对话框时执行以下操作:

using (var frm = new MyCustomForm())
{
    //This is a blocking call - the execution stops here until that
    //form is closed and you can then examine the result
    var result = frm.ShowDialog();  
}

See https://msdn.microsoft.com/en-us/library/c7ykbedk%28v=vs.110%29.aspx for more information on ShowDialog method. 有关ShowDialog方法的更多信息,请参见https://msdn.microsoft.com/zh-cn/library/c7ykbedk%28v=vs.110%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM