• 0

[VB .NET] Loading a form on button click


Question

6 answers to this question

Recommended Posts

  • 0

That code is quite valid, but you can also do:

Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
   Dim loForm As New Form1
   Application.Run(loForm)
End Sub

I think the "Show" function is there for backwards compatibility with old VB code, i'm not 100% sure though.

  • 0
  kronos said:
That code is quite valid, but you can also do:

Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
   Dim loForm As New Form1
   Application.Run(loForm)
End Sub

I think the "Show" function is there for backwards compatibility with old VB code, i'm not 100% sure though.

585795236[/snapback]

Application.Run is for beginning a new application, meaning that the form will have its own message loop. Total overkill. Show() or ShowDialog() are the correct ways of showing a form.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.