将文本值传递给另一个表单文本框 [英] Passing Text Value to another form textbox

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

问题描述



如何将文本从表单(forma)上的一个文本框传递到另一表单(formb)上的另一个文本框.

我没有犯错,但是文字消失了,没有出现在其他表格上.

Hi,

How do you pass text from one textbox on a form (forma) to another textbox on another form (formb).

i am not getting an eror but the text just disappear and doesnt appear on the other form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     txtAto.Text = formmail.txtto.Text
 End Sub



是我没有正确执行某些操作吗:S



is ther somethings i am not doing correctly :S

推荐答案

您的代码与您说的相反.您的代码将其他窗体的文本框中的文本分配给当前窗体的文本框中(但是,如果我理解正确的话,您将尝试执行相反的操作).

通常,直接访问另一种形式的控制变量不是一个好主意.最好公开一种公共方法,例如另一种形式的 SetSomeText(string text),该方法会在内部将文本分配给正确的文本框.
Your code''s doing the reverse of what you say you need to do. Your code assigns the text from the other form''s textbox to your current form''s textbox (but you are trying to do the opposite if I understand it right).

In general it''s not a good idea to access another form''s control variables directly. It may be better to expose a public method, something like SetSomeText(string text) in this other form that will internally assign the text to the right textbox.


添加公共property形成表格b.然后您可以执行以下操作:
Add a public property to form b. Then you can do something like:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     formB.PassedText = formmail.txtto.Text
 End Sub


这假定Form b上的属性称为PassedText,并且Form b由Form A创建.如果不是,则请描述您的应用程序的结构.

然后在您财产的二传手中


This assumes that the property on Form b is called PassedText and that Form b is created by Form A. If it is not then please describe the structure of your application.

Then in the Setter of your property

txtAto.Text = Value



希望对您有所帮助.



Hope this helps.


您认为这更复杂.

为此,您必须有权访问两个表单实例:不是定义,而是访问正在运行并保存所需信息的表单的实际实例.

使用您的名字:

假设您的按钮"button1"位于"formb"上,那么如果"formmail"包含"forma"的实例,那么您可以这样做.

首先要检查的是:您是否在复制正确的方法?您要在TextBox中复制的文本是"txtto",还是要在另一表格上放置"txtAto"的地方?

在复制指令上放置一个断点,然后检查.

尝试访问其他表单控件的内容不是一个好主意:它将两个表单紧密地捆绑在一起.您不能不检查就更改一个不会影响另一个.
而是使用属性:
This is more complex that you think.

In order to do this, you must have access to both form instances: not the definitions, but the actual instance of the form that is running, and holds the information you want.

Using your names:

Assuming that your Button "button1" is on "formb", then if "formmail" contains the instance of "forma" then you can do it.

The first thing to check is: are you copying the right way? Is the text you want to copy in the TextBox "txtto" and the place you want to put it "txtAto" on the other form?

Put a breakpoint on the copy instruction, and check.

It is not a good idea to try accessing the content of other form controls: it ties the two forms too tightly together. You can''t change one without checking is doesn''t affect the other.
Instead, use a property:
Public Property ToAddress() As String
    Get
        Return tbToAddress.Text
    End Get
    Set
        tbToAddress.Text = value
    End Set
End Property

,然后访问它.


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

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