我如何从表单1中获取控件的值,并在VBnet winform应用程序中的表单2中使用它 [英] How I do get value of control from form 1 and using it in form 2 in VBnet winform application
本文介绍了我如何从表单1中获取控件的值,并在VBnet winform应用程序中的表单2中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何从表单1获取控件的值并在VBnet winform应用程序中的表单2中使用它
How I do get value of control from form 1 and using it in form 2 in VBnet winform application
推荐答案
究竟如何取决于关于表格之间的关系。如果您考虑打开另一个表单作为父母打开孩子的表单,请查看以下内容:
在两种形式之间传递信息,第1部分:父母对儿童 [ ^ ]
在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]
在两种表格之间传递信息,第3部分:儿童与儿童 [ ^ ]
它们在C#中,但原理在VB中完全相同。
Exactly how depends on the "relationship" between the forms. If you think about a form which opens another form as a Parent opening a Child, then have a look at these:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
They are in C#, but the principle is exactly the same in VB.
假设你没有打开form2,你按一个按钮打开它
在form1中(示例目的)我有一个文本框和两个按钮。
按钮1将文本框中的文本保存到字符串属性中,
按钮2打开表单2
Let's say you don't have form2 open, and you press a button to open it
In form1 (example purposes) I have a text box and a two buttons.
Button 1 saves text from the textbox into a string property,
Button 2 opens Form 2
Public Class Form1
Property TextFromForm1 As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextFromForm1 = txtString.Text
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Hide()
Form2.Show()
End Sub
End Class
加载表单2时,会出现一个文本框,显示从中传递的文本Form1
使用:
When Form 2 loads, there is a text box that shows the text passed across from Form1
using:
TextForForm2 = Form1.TextFromForm1
TextBox1.Text = TextForForm2
希望这有帮助......让我来吧知道如果我理解错误的问题(New Here)
Hope this helps... Let me know If I'm understanding the question wrong (New Here)
我通常选择一个有一些PUBLIC变量的小型处理表格。通常这是我的启动表单,我只是隐藏,直到我关闭实际的应用程序。所以代码如下:
I normally opt for a small handling form that has some PUBLIC varibles. Normally this is my startup form that I just hide till I close the actual application. So the code would be as follows.
Public Class Form1
Public myInfo as string="" 'Going to pass this varible on the opening of the other form.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
myInfo="Hello World"
Me.Hide()
Form2.Show()
End Sub
End class
第二种表格会有此代码。
The second form would have this code.
Public Class Form2
Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
msgbox(myInfo) 'Display the information we just passed.
End Sub
End class
这篇关于我如何从表单1中获取控件的值,并在VBnet winform应用程序中的表单2中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文