将数据从form1中的文本框传递到visual basic中打开的form2中的文本框 [英] passing data from textbox in form1 to textbox in opened form2 in visual basic

查看:27
本文介绍了将数据从form1中的文本框传递到visual basic中打开的form2中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有form1来输入电影详细信息

i have form1 to enter movies details

在这个 form1 中,我有一个名为 NVideosGenres 的文本框

in this form1 i have a textbox called NVideosGenres

通过这个文本框我可以用空格打开form2

through this textbox i can open the form2 with a space

form2 包含 5 个组合框,让用户选择类型(如果有多个)

the form2 contains 5 combobox to let the users choose the genres if there is more then one

当用户选择流派时,它们将以相同的形式应用于文本框

when user choose the genres they will be applied to a textbox in the same form like this way

例如我从三个组合框中选择

for example i choose from three combobox

动作 - 战争 - 西部

action - war - western

所以现在我有一个问题,因为我知道要传递值我应该这样做

so now i have a problem because i know that to pass value i should do this

Videos.NVideosGenres.text = me.FinalGenres.text
me.close()

当我点击按钮时,form2 将关闭,但数据不会传递到 form1 中的 NVideosGenres

when i click on the button the form2 will close but the data don't pass to NVideosGenres in the form1

有什么帮助吗??

推荐答案

有很多很多方法可以做到这一点.最简单的方法之一是在 Form2 上创建一个属性,该属性包含对主调用表单的引用.然后你可以直接从 Form2 设置文本框(或其他)的值.这绝对不是最好的方法,但它肯定是快速和容易的.

There are many, many ways to do this. One of the easiest ways would be to create a property on Form2 that holds a reference to your main calling form. Then you can set the values of the textboxes (or whatever) directly from Form2. This is definitely not the best way to do it, but it certainly is quick and easy.

Private Sub btnShowForm2_Click(sender As System.Object, e As System.EventArgs) Handles btnShowForm2.Click
   'Create a new instance of Form2 (called frmDetail in this example).
   Dim frm2 As New frmDetail()
   'Set the MyParentForm property of Form2 to this form.
   frm2.MyParentForm = Me
   'Show the form.
   frm2.ShowDialog()
End Sub

现在在 Form2 中,当您单击确定"按钮关闭表单时,您可以使用引用父表单的属性直接设置值.

Now in Form2, when you click the "OK" button to close the form, you can use the property that references your parent form to set the values directly.

' Property to hold a reference to the calling form.
Private mParentForm As frmMain
Public Property MyParentForm() As frmMain
    Get
        Return mParentForm
    End Get
    Set(ByVal value As frmMain)
        mParentForm = value
    End Set
End Property

' When I click the OK button, I will store the value of my various textboxes to properties.
Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
    'Set the value of the Genre textbox on the parent form to the value
    'of the textbox on my current form.
    MyParentForm.txtGenre.Text = txtGenre.Text
    Me.Hide()
End Sub

这篇关于将数据从form1中的文本框传递到visual basic中打开的form2中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆