如何在vb.net中制作自我复制程序?

时间:2017-08-16 15:59:07

标签: vb.net

我正在尝试制作一个小恶作剧程序,其中一个表单一直打开,直到达到某个数字,如50或其他什么,我试过这个:

Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Show()
    End Sub
End Class

但那不行,有谁愿意帮忙?感谢

1 个答案:

答案 0 :(得分:0)

同样的litelite说。如果要显示表单的实例,则Show()不会删除它。

事实上,一旦你关闭那个表格,你正在使用的计时器就会丢失。因此,您还需要处理Form.Closing事件。因为我们只是在这里玩得开心,所以我建议你做的工作就像切断Hydra的头部,再多做两次。

尝试这样的事情:

Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim _newForm as Form2 = new Form2()
        _newForm.Show()
    End Sub

    Private Sub Me_Closing(sender As Object, e As EventArgs) Handles Form2.Closing
        Dim _newForm as Form2 = new Form2()
        _newForm.Show()
        Dim _newForm2 as Form2 = new Form2()
        _newForm2.Show()
    End Sub
End Class