将值从usercontrol传递到表单 [英] Passing values from usercontrol to form

查看:63
本文介绍了将值从usercontrol传递到表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我有UserControl1和Form2我想要的是将textbox1值从usercontrol1传递到textbox1在Form2中。(我有很多值可以通过)



我的尝试:



textbox1.Text = UserControl1.textbox1.text

解决方案

不要将控件UI对象暴露给外部表单,这意味着如果不考虑它对外部世界的影响,就无法修改控件。相反,在你的控件中添加一个表单可以访问的属性,它可以用它做它喜欢的东西。

如果控件需要启动进程,那么还要添加一个表单的事件订阅 - 表单然后通过事件处理程序方法中的属性来处理数据。



这样,控件不会锁定到一个表单并且可以必要时可以重复使用 - 这是一个很好的OOP设计。


真的非常感谢,我就是这样做的:



 私有  Sub  Button1_Click(发件人作为 对象,e 作为 EventArgs)句柄 Button1.Click 
Dim frm As SbillPrint
frm.smoney_tx t.Text = moneys_txt.Text
frm.ShowDialog()
结束 Sub


I have a small problem, I have UserControl1and Form2 what I want Is passing textbox1 value from the usercontrol1 to textbox1 In the Form2 .(i have many values to pass)

What I have tried:

textbox1.Text = UserControl1.textbox1.text

解决方案

Do not expose the control UI objects to external forms, that means you can't modify the control without considering its affects on the outside world. instead, add a property in your control which the form can access, and it can do what it likes with it.
If the control needs to start the process, then also add an event to which the form subscribes - the form then addresses the data via the property in the event handler method.

That way, the control isn't "locked" to the one form and can be reused as necessary - which is good OOPs design.


Thanks for All really, this is how i done it :

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim frm As New SbillPrint
        frm.smoney_txt.Text = moneys_txt.Text
        frm.ShowDialog()
End Sub


这篇关于将值从usercontrol传递到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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