模态和非模态形式的项目级概念 [英] Project level conception of modal and nonmodal forms

查看:19
本文介绍了模态和非模态形式的项目级概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由多个表单组成的项目,我想以某些我无法实现的模态规则打开它.

I have project which consist of several forms and want to open it in certain modality rules which I can't achieve.

首先,这里是主表单Form1",然后是Form11"和Form111",Form12"和form121"

First, here is main form "Form1", then "Form11" and "Form111", "Form12" and "form121"

从主表单Form1"我只能开始像这样的表单Form11"和Form12":

From main form "Form1" I can start only forms "Form11" and "Form12" like this:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form11.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Form12.Show()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Me.Close()
End Sub
End Class

在这种情况下,当显示Form11"和Form12"时,我可以通过按下Form1"上的 Button4 来轻松退出应用程序,这将关闭所有表单.

In this situation, when "Form11" and "Form12" are showed I can easily exit application by pressing Button4 on "Form1" what will close all forms.

现在,这是另一种形式,Form111",我通过单击Form11"上的按钮以模态打开它...

Now, here is another form, "Form111" which I open modally by clicking a button on "Form11"...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim f As New Form111
    f.ShowDialog(Me)
    f = Nothing
End Sub

这里我对我的项目有一些误解或误解.

And here I have some misunderstanding or misconception of my project.

当Form111"打开时,我喜欢它阻止Form11"而不是Form1",我想(比如)打开Form2"或退出应用程序,其中非模态表单Form11"上的模态表单Form111"是打开.

When "Form111" is opened I like it to block "Form11" but not "Form1" where I would like to (say) open "Form2" or exit application where modal form "Form111" on nonmodal form "Form11" is opened.

是否可以通过描述的项目配置以及如何实现这样的功能?

Is it possible to achieve such functionality with described project configuration and how?

推荐答案

首先,第一块中按钮点击的代码可能不对.如果表单被命名为 Form11Form12,那就是它们的类名.它们应该像使用 Form111 一样被实例化.

First, the code for the button clicks in the first block may not be right. If the forms are named Form11 and Form12 that is their class name. They should be instanced as you do with Form111.

应用程序关闭的原因是因为该表单 (Me) 被设置为启动表单.如果/当它关闭时,应用程序结束.您可以在项目属性中将应用更改为在最后一个表单关闭时退出.

The reason the application closes is because that form (Me) is set as the startup form. If/when that closes, the app ends. You can change the app to exit when the last form closes in project properties.

至于你的问题,有一个对话框阻止"Form11"而不是Form1",答案是否定的.表单要么是Modal(你称之为阻塞"),要么是Modeless.您可以告诉 Form111 保持在最前面,但它不会阻止"任何其他表单.

As for your question, to have a dialog "block" "Form11" but not "Form1", the answer is no. Forms are either Modal (what you are calling "blocking") or Modeless. You could tell Form111 to stay on top, but it would not be "blocking" any other form.

您正在尝试做的事情表明,这些表单上的操作可能没有像它们需要的那样组织或计划得很好.

What you are trying to do suggests that the operations on these forms may not be as well organized or planned as they need to be.

这篇关于模态和非模态形式的项目级概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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