简体   繁体   English

如何防止当前表单之外的点击?

[英]How to prevent clicks outside the current form?

我想要当用户单击按钮时将打开的表单,我不希望用户单击此表单之外的其他任何位置(防止他单击父表单上的任何其他按钮),我想限制其在此表单内的操作表单,直到他关闭该表单(确保此表单是最顶部),并且我希望该表单对表单外部的任何点击发出警报(闪烁),以便用户理解他必须首先关闭它。

When opening the form instead of 当打开表单而不是

Form form = new Form();
form.Show();

use 采用

Form form = new Form();
form.ShowDialog()

Super easy fix! 超级容易修复! I assume your code to show the form right now is 我假设您现在显示表单的代码是

form.Show();

To create/show an instance of the form that is modal (restricts clicking to that form) all you need to change is that line to: 要创建/显示模式表单的实例(限制单击该表单),您只需要将以下行更改为:

form.ShowDialog();

Liam 利亚姆

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

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