如何在Windows应用程序中将文本框值从一种形式转移到另一种形式? [英] How to transfer a textbox value from one form to another in a windows application?

查看:98
本文介绍了如何在Windows应用程序中将文本框值从一种形式转移到另一种形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows应用程序.在该应用程序中,我使用两种形式.我需要从第二个表单获取第一个表单的texbox的text属性.

在Web应用程序中,我们使用会话.在Windows应用程序中,我可以使用什么代替会话?

请给我一些想法或一个示例解决方案.

I''m developing a windows application. In that application I''m using two forms. I need to get the text property of a texbox on the first form from the second form.

In web applications we use sessions. What can I use instead of sessions in a windows application?

Please give me some idea or a one sample solution.

Thanks

推荐答案

在窗口应用程序中,您必须将值传递到其他页面的Constructor .

只需假设

如果要从Form1 传递到Form2
呼叫Form2 like

In window application you will have to pass the value to the Constructor of other page.

Simply assume

if you want to pass from Form1 to Form2
call Form2 like

Form2 form2 = new Form2(txtTest.Text);



constructor 放在接收方



put constructor at receiving side

Class Form2
{
Form2(string tempText)
{
txtTest.Text = tempText;
}
}



和您完成了.

如果有帮助,请 投票 接受答案 .



and your''e done.

Please vote and Accept Answer if it Helped.


希望它可以满足您的需求.

Hiren的答案也很漂亮.
Hope it may satisfies your need.

Hiren''s Answer is also an beautiful one.
For Assumption:
In Form1 Declare
public static string TextboxText;

If i Click on Button1 of Form1

i am going to Capture Textbox1.Text in TextboxText
ie
TextboxText= Textbox1.Text;

When i open Form2
Just assign TextboxText to Textbox2 in Form2
ie

Textbox2.Text=Form1.TextboxText;


u可以通过形式的usind对象尝试此操作. 像form1.show();
u can try this by usind object of the form..
like form1.show();


这篇关于如何在Windows应用程序中将文本框值从一种形式转移到另一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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