VB程序员。我有表格导航的问题

时间:2013-05-04 23:10:08

标签: vb.net winforms

我的程序中有几个表单,我显然也有导航。下一步和后退按钮。我有NEXT按钮编码如下:

Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
    ' Closes current screen and opens the next

    Me.Visible = False
    Form4.ShowDialog()
End Sub

BACK按钮如下:

Private Sub BackButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackButton.Click
    ' Closes current screen and opens the previous screen
    Me.Visible = False
    Form2.ShowDialog()
End Sub

正如您所知,这是来自Form3。

因此。我前进很好,但是一旦我回击我的程序就不想跑了。

我做错了什么?

2 个答案:

答案 0 :(得分:2)

在VB中使用“ShowDialog”显示表单时,您必须评估响应并关闭表单。仅将Visible设置为false是不够的。

请参阅此处的代码: http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

您可能只想显示表单,而不是showDialog,这里有示例: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.show.aspx

希望有所帮助。

答案 1 :(得分:1)

如果你必须使用OpenDialog,这里有一个如何实现这个的例子:

首先,需要在load事件中设置对Form1的引用。必须首先在Form2中创建引用(见下文):

Public Class Form1
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Form2.f1 = Me
    End Sub

Private Sub Next_Click(sender As System.Object, e As System.EventArgs) Handles ButNext.Click
    Me.Visible = False
    Form2.ShowDialog()
End Sub

在Form2中,创建在Form1的load事件中设置的Form1公共变量。在Previous按钮处理程序中,将对Form1的visible属性的引用设置为True,而不是调用ShowDialog。

Public Class Form2
    Public Property f1 As Form1 ' you can also create a variable instead of a property

    Private Sub Previous_Click(sender As System.Object, e As System.EventArgs) Handles ButPrev.Click
        f1.Visible = True
        Me.Visible = False
    End Sub

    Private Sub ButNext_Click(sender As System.Object, e As System.EventArgs) Handles ButNext.Click
        Me.Visible = False
        Form3.ShowDialog()
    End Sub

    Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        ' repeat process for Form3
        Form3.f2 = Me
    End Sub
End Class

对应用程序中的所有对话框表单重复此过程。