从不同的表单中获取不同的表单控制值 [英] Fetch different form control value from different form

查看:67
本文介绍了从不同的表单中获取不同的表单控制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,

我正在Windows应用程序中工作.

我的问题是:我有5种表格.在第一种形式中,我在文本框中输入了一些值.我想使用C#以我的第五种形式获取此文本框值.

hai,

I am working in windows application.

My question is: I have 5 forms. In first form i entered some value in the textbox. I want to get this textbox value in my 5th form using c#. how to acheive it?

推荐答案

在Windows应用程序中,可以使用属性"或使用参数化构造函数"来实现.

使用参数化构造函数
---------------------
在Form1的按钮单击事件上编写以下代码
In case of Windows application, Either you can use Properties or Use parameterised constructor to do the same.

Using Parameterised Constructor
---------------------
Write the following code on button click event of Form1
Form5 f=new Form5(textBox1.Text);
f.Show();

Get the value in the Form5 as
string sValue;
public Form5(string s)
{
   sValue=s;
}


使用属性
-------------------
在Form2中将属性定义为


Using Properties
-------------------
Define the property in Form2 as

private string sValue;
public string Value
{
    get{return value;}
    set{value=sValue;}
}


并同时使用变量的值.

在Form1中将textBox1的值设置为:


and use the value of the variable as well.

Setting the value of textBox1 in Form1 as:

Form2 f=new Form2();
f.Value=textBox1.Text;


否.我认为我们不能在Windows应用程序中使用会话.我想在我的第五个表单中获取第一个表单的文本框值.怎么办?

谢谢
No. I think we can not use session in windows application. I want get first form textbox value in my fifth form. how to do?

Thanks


这篇关于从不同的表单中获取不同的表单控制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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