在vb.net中的两种形式之间传递值 [英] Pass value between two form in vb.net
问题描述
朋友们,
我有一个项目,其中有两个窗体Form1和Form2.
我在form1的EmpName编码上有一个变量,并且我想使用以下编码在Form1的按钮单击上显示Form2,并且还想在Form2的标签lb1上显示上述变量的值.
我用来显示Form2的代码是..
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..
Private Sub btn_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Search.Click
Form2.ShowDialog()
End Sub
请帮帮我...
在此先感谢
Parveen Rathi
Please help me...
Thanks in advance
Parveen Rathi
推荐答案
在.NET中的表单之间传递值1.x,带有C#和VB.NET示例 [ ^ ]
在表单之间传递数据 [
Passing Values between Forms in .NET 1.x with C# and VB.NET examples[^]
Passing Data Between Forms[^]
有两种方法:
1.使用构造函数将值用作输入
2.使用属性
签出:
1. 在表单之间传递数据 [在表单之间传递值 [ ^ ]
3. VB.NET-在表单之间传递数据 [ ^ ]
4. 传递一些数据并在表单之间返回一些数据. [
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.
在Form1的Button Click上写以下代码
Write the following code on Button Click of Form1
'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
在Form2类上编写以下代码
Write the following code on Form2 class
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
以及有关Form2的Load事件的以下代码
and the following code on Load event of Form2
Private Sub Form2_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = eid.ToString()
End Sub
这篇关于在vb.net中的两种形式之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!