Rize S. answered 03/23/23
Senior IT Certified Trainer, IT Developer & DBA Administrator
Sure, here's an example of how you can use Visual Basic to click a button and open a new form in Visual Studio 2019:
- Open Visual Studio 2019 and create a new Windows Forms App (.NET Framework) project.
- In the Solution Explorer, right-click on the project name and select Add > Windows Form. This will create a new form named "Form2".
- Open "Form1.vb" in the designer view, and drag a Button control from the Toolbox to the form.
- Double-click the button to create a new click event handler method.
- In the method, add the following code to create an instance of "Form2" and show it:
Dim form2 As New Form2()
form2.Show()
- Save the file and run the application. Clicking the button should now open "Form2".
Here's the complete code for the "Form1.vb" file:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim form2 As New Form2()
form2.Show()
End Sub
End Class
That's it! You can modify this code to suit your needs, such as passing data between forms or customizing the appearance of the forms.