简体   繁体   中英

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

I'm currently building a winforms application. 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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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