vb 表单重新出现而无需请求 [英] vb form re-appearing without requesting

查看:34
本文介绍了vb 表单重新出现而无需请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将问题缩小到这个简单的案例,但似乎无法找到发生了什么:

I have narrowed my problem to this simple case, but can't seem to find what's going on:

  • 我有两个表单,一个按钮打开,另一个为空.
  • 点击按钮后,form1 隐藏并显示 form2
  • 出现时,form2 将隐藏,并再次显示 form1

另外,当输入VisibleChanged时,Form2会以MsgBox停止代码如下.

In addition, when entering VisibleChanged, Form2 will stop with a MsgBox The code follows.

现在预期的行为,当点击按钮时

Now the Expected behavior, when clicking on button would be

  • Form1 隐藏
  • 第一个 MsgBox 由于 Form1 调用 Form2.show 使可见变为真
  • 由于 Form2 调用 Me.hide 导致可见的第二个 MsgBox 变为 false
  • Form1 出现

这一切都发生了,但是,

all this does happend, but then,

  • Form2 出现(Form1 还在)
  • 出现一个 msgbox(再次告诉 form2.visible 为 True)
  • 出现一个 msgbox(现在告诉 form2.visible 是 False)
  • Form2 隐藏

知道为什么吗?

代码如下:

Public Class Form1
    Private Sub ButtonGO_Click(sender As Object, e As EventArgs) Handles ButtonGO.Click
        Me.Hide()
        Form2.Show()
    End Sub
End Class

还有

Public Class Form2
    Dim calls As Integer = 0
    Private Sub Form2_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
        calls += 1
        MsgBox("calling : " & calls & " / Me.Visible : " & Me.Visible)
        If Me.Visible Then
            Me.Hide()
            Form1.Show()
        End If
    End Sub
End Class

推荐答案

好的,为了结束:感谢您的回答,他们告诉了完整"的 VB 编码器该怎么做.

Ok, so in order to close : thanks for your answers, they tell what to do for a "full" VB coder.

对于我的学生,即只使用拖放式VB的人,解决方案是检查Form1中的条件,然后在Form2出现时调用.

As for my students, i.e. people who just use drag-n-drop-VB, the solution is to check conditions in Form1 and then only call Form2 when it will show up.

注意:这可能看起来微不足道,但它可能不符合封装"的想法.这就是在我的案例中首先提出这个问题的原因.

Note : This might seem trivial, but it may not be compliant with the "encapsulation" idea. That is what brought this issue up in the first place in my case.

这篇关于vb 表单重新出现而无需请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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