In this blog we will learn How to pass data one form to another in Windows Form using VB.Net
Here Laxmikant has explained about How to pass data one form to another in Windows Form using VB.Net
Step 1 : Drag and drop a Label, a TextBox, a Button and a ComboBox from the Toolbox. I have created a Form with 3 Labels, a TextBox, a button and a ComboBox as shown in the following snapshot.
Step 2 : Please Click on Edit items and after that we will add items in the ComboBox as shown in the following screenshot.
Step 3 : Please write the following code in Form1.vb page.
I have a Name, Email and Select Hobbies label on the form. So i am using three global variables.
Public Shared name As String
Public Shared email As String
Public Shared selectedHobbies As String
Step 4. Double-click on the Save button on the Windows Form1 and write the code.
Notes : ConfirmationForm is the name of another form.
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
name = txtName.Text
email = txtEmail.Text
selectedHobbies = cmbhobbies.Text
Dim confirmation As ConfirmationForm = New ConfirmationForm()
Step 4 : Add another Windows Forms form using Project –> Add Windows Form then click on Add.
Step 5 : Drag and Drop 6 Labels from the Toolbox onto ConfirmationForm.
Step 5 : Double-click on ConfirmationForm and write the code of load event:
Private Sub ConfirmationForm_Load(ByVal sender As Object, ByVal e As EventArgs)
labelName.Text = Form1.name
labelEmail.Text = Form1.email
labelHobbies.Text = Form1.selectedHobbies