如何创建一个新表单并使所有其他表单在处理该表单之前不可点击? [英] How to create a new form and make all other forms not clickable until that form is disposed?
问题描述
我曾经读过一个关于如何创建一个新表单并将其置于所有其他窗口之上的教程,这样您就可以只单击它 - 例如在 Internet Explorer 中,当您单击浏览文件时,您无法单击主窗口窗口,直到您完成浏览窗口的使用.
I once read a tutorial about how to create a new form and make it above all other windows so you can click only it - like in internet explorer for example when you click on browse for a file you can't click the main window until you finish using the browse window.
还有什么是从表单中获取值的最佳方法,例如在我的第二个表单上,我有一个列表框,当用户单击其中一个值时,第一个表单(主表单)应该获取事件 - 这是可能吗?
Also what is the best way to get values from a form back, for exmpale on my second form I have a listbox and when a user clicks on one of the values the first form (mainform) should get the event - is this possible?
推荐答案
您正在寻找的是将表单显示为模态对话框.Form.ShowDialog()
在这里您可以阅读更多相关信息主题.
What you are looking for is to show the form as a modal dialog box. Form.ShowDialog()
Here you can read more about this topic.
您可以通过以下几种方式访问父表单(后表单):
You can access parent form (back form) in couple ways:
- 使模态表单构造函数接受父级作为参数
- 将父表单引用放入一些可以从模态表单访问的全局变量中
- ...
要从子表单获取事件,您可以执行以下操作:
To get an event from child form you can do something like this:
form.myListBox.SelectedIndexChanged += new System.EventHandler(this.myListBox_SelectedIndexChanged);
form.ShowDialog();
您需要将 myListBox 控件设为公开才能从父(调用者)表单访问它.
You need to make myListBox control public in order to access it from parent (caller) form.
这篇关于如何创建一个新表单并使所有其他表单在处理该表单之前不可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!