使用C#从另一种形式获得的值 [英] Getting a value from Another Form using C#

查看:109
本文介绍了使用C#从另一种形式获得的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何从一种形式,另一种形式的价值?
我已经试过以下,但它不工作



Form1中:

 公开文本框TXT()
{
{返回txtbox1;}
}

窗体2:

 公共Form1中FRM; 

txtbox2.Text = frm.TXT.Text;


解决方案

您声明Form1的txtbox1修改为public。而在Form2的声明如下:

  System.Windows.Forms.Form中F = System.Windows.Forms.Application.OpenForms [ Form1的]; 



然后:

  txtbox2.Text =((Form1中)F).txtbox1.Text; 


How do you get a value from one form in another form? I've tried the following but it doesn't work.

Form1:

public TextBox TXT()
{
get{return txtbox1;}
}

Form2:

public Form1 frm;

txtbox2.Text=frm.TXT.Text;

解决方案

Declare your Form1's txtbox1 Modifier as public . And in Form2 Declare the following:

System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["Form1"];

Then :

txtbox2.Text = ((Form1)f).txtbox1.Text;

这篇关于使用C#从另一种形式获得的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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