vb.net 在 Windows 窗体中将窗体链接回上一个窗体的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20382590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:01:10  来源:igfitidea点击:

Code linking a form back to previous form in Windows Forms

vb.netwinformsvisual-studio-2010hyperlinkback

提问by

Having a problem linking my form3 back to form2 in windows forms. I want the "back" button to take me back to form 2 but it doesnt do so. I am trying form2.show() but it doesnt work.

在 Windows 窗体中将我的 form3 链接回 form2 时出现问题。我希望“后退”按钮将我带回表格 2,但它没有这样做。我正在尝试 form2.show() 但它不起作用。

My current form3 code:

我目前的 form3 代码:

Public Class Form3

    Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged
        MessageBox.Show("Developer Succsessfully Added to Sprint", "Developer Added")
    End Sub

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        **Form2.Show()**
    End Sub
End Class

采纳答案by T.S.

What happening is most likely you already closed your form and can't open it again.

发生的情况很可能是您已经关闭了表单并且无法再次打开它。

Assuming, you have both instances well and alive

假设,你有两个实例都很好而且还活着

In Form2 you should have

在 Form2 你应该有

me.Hide()
Form3.Show()

And In Form3 you should have

在 Form3 中你应该有

me.Hide()
Form2.Show()

It can be something like this

它可以是这样的

shared sub Main
    dim f2 as new Form2()
    dim f3 as new Form3()

    f2.Next = f3
    f3.previous = f2

end sub

To link forms you creating properties, Nextand PreviousAnd then use that as way to operate the form that should open

要链接的形式,你创建的属性,NextPrevious再使用它作为方式操作,即应打开窗体

In form code do

在表单代码中做

private sub BtnNext_Click(....).....
    Me.Hide()
    Me.Next.Show()
End Sub

and the same way for the previous. If you have wizard, you could chain all your forms this way. and of course, to accomplish this, minimum, you need an interface that contracts your forms to implement Properties Nextand Previousor you can have a base class with implementation of the buttons and properties and then it will all work.

和以前的方式相同。如果您有向导,则可以通过这种方式链接所有表单。当然,为了实现这一点,至少,您需要一个接口来收缩您的表单以实现属性NextPrevious或者您可以拥有一个带有按钮和属性实现的基类,然后它就会全部工作。

回答by user8487636

simple code redirect one form1 to form2 Using C#

简单的代码使用 C# 将一个 form1 重定向到 form2

Form2 f2=new Form2();

Form2 f2=new Form2();

f2.show() OR f2.ShowDialog();

f2.show() 或 f2.ShowDialog();