在Windows窗体之间传递数据 [英] Passing Data between Windows Forms

查看:80
本文介绍了在Windows窗体之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道如何在两个窗体之间传递文本。我目前正在使用带有.net框架的vb.net 4.我有一个带有2个按钮的主窗体(btnbrowse,btnclose)& 2个文本框(txtName,txttype)。当用户点击btnbrowse我想要form2(对话框)时,显示然后用户可以从组合框中选择项目。当用户点击确定时,我希望它将数据传回txttype上的MAINFORM。



 公开 属性 PassType 作为  String  
获取
返回 txttype.Text
结束 获取
设置 ByVal value 作为 字符串
txttype .Text = value
结束 设置
结束 物业







 私人  Sub  Button1_Click( ByVal  sender  As  System。对象 ByVal  e  As  System.EventArgs)句柄 Button1.Click 
MAINFORM.TXTTYPE.TEXT = PassType
Me .Close()
结束 Sub





它仍然不起作用......这有什么问题......因为我迷惑自己...任何帮助都会很棒。



提前谢谢。

解决方案

这是一个很受欢迎的表格协作问题。最强大的方法是在表单类中实现适当的接口。



请参阅我过去的解决方案解释:如何以两种形式复制列表框之间的所有项目 [< a href =http://www.codeproject.com/Questions/180489/How-to-copy-all-the-items-between-listboxes-in-two.aspx\"target =_ blanktitle =新窗口> ^ ]。



-SA


问题随之而来非常受欢迎,我以前的答案往往不太清楚,可能还不够清楚,我决定写一篇提示/技巧文章,详细的代码示例和解释:一次回答的许多问题 - Windows窗体或WPF Windows之间的协作



-SA

Hi All,

I was wondering how can i pass text between two windows forms. i am currently using vb.net with .net framework 4. I have a mainform with 2 buttons (btnbrowse, btnclose) & 2 textboxs(txtName, txttype). When the user clicks btnbrowse i want form2 (dialogbox) do show and then the user able to select item from combobox. when the user clicks ok i want it to pass the data back to MAINFORM on txttype.

Public Property PassType As String
    Get
        Return txttype.Text
    End Get
    Set(ByVal value As String)
        txttype.Text = value
    End Set
End Property




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MAINFORM.TXTTYPE.TEXT = PassType
        Me.Close()
    End Sub



it still does not work...is there something really wrong with this....cos im confusing my self...any help would be great.

thanks in advance.

解决方案

This is a popular question of Form collaboration. The most robust way of doing it is implementation of appropriate interface in the form class.

Please see my past solution explaining that: How to copy all the items between listboxes in two forms[^].

—SA


As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—SA


这篇关于在Windows窗体之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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