Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I have a project in which I have two window forms Form1 and Form2.

I have a variable on form1 coding EmpName, and I want to show the Form2 on a button click of Form1 using the following coding and also want to show the value of above mentioned variable on a label lb1 which is on Form2.

The code I'm using for show the Form2 is..

VB
Private Sub btn_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Search.Click
        Form2.ShowDialog()
End Sub


Please help me...



Thanks in advance
Parveen Rathi
Posted
Updated 12-Sep-11 18:42pm
v4
Comments
Dalek Dave 12-Sep-11 3:27am    
Edited for Clarity.

 
Share this answer
 
Comments
Dalek Dave 12-Sep-11 3:27am    
Nice Link.
There are two ways to do so :
1. Use the constructor to take the value as input
2. Use the property

Check out :
1. Passing Data Between Forms[^]
2. Passing values between forms[^]
3. VB.NET - Pass data between forms[^]
4. Pass some data and return some data across the forms.[^]

Hope this helps.
All the best.
 
Share this answer
 
Write the following code on Button Click of Form1
VB
'Declare a variable of string type
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pass As String = "Head"
        Dim frm As New Form2(pass)
        frm.ShowDialog()

    End Sub


Write the following code on Form2 class
VB
Dim eid As String = ""
    Public Sub New(ByVal empid As String)
        InitializeComponent()
        eid = empid
    End Sub


and the following code on Load event of Form2
VB
Private Sub Form2_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = eid.ToString()
    End Sub
 
Share this answer
 
Dear Pravin Patil,


Dear getting this warning



Warning 1:The field 'pars.Form2.label5' is never used
 
Share this answer
 
 
Share this answer
 
You can use module class in vb.net, File -> Add New Item -> Module class, and declare all global variables here and you can use these variable any where in the current project.

In case of C# you can add a class file and declare the required variable static like Static int id. and use it any where in the project like global.id, here global is my class name where the id variable is declare
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900