如何通过其他形式设置值 [英] How to set values from another form

查看:76
本文介绍了如何通过其他形式设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种窗口形式.例如. form1和form2.
我想用form1文本框中的值在form2中设置标签值.

如何设置值.

I have two window forms. eg. form1 and form2.
I want to set the label value in the form2 with the value from the text box in form1.

How can I set the values.

推荐答案

您需要向要访问的表单添加方法(或属性).然后,您可以从第一种形式访问这些方法/属性.不要使用公共控件-这不是最佳解决方案.
You need to add a method (or a property) to the form that you want to access. You can then access these method/property from the first form. Don''t use public controls - this is not the best solution.


Hiya,

在表2中,为标签创建一个属性:


例如
按下:< ctrl>< space>
前往:prop
按下:< tab>两次
这将创建一个属性:

例如
Hiya,

In form 2 create a property for your label:


E.g.
press: <ctrl><space>
go to: prop
press: <tab> twice
This will create a property:

E.g.
// Property for Label1
public string MyLabel1
{
  get { return label1.Text; }
  set { label1.Text = value; }
}



您可以按以下方式从form1访问和设置此属性:



You can access and set this property from form1 as follows:

private void button1_Click(object sender, EventArgs e)
{
  Form2 Form2 = new Form2();
  Form2.MyLabel1 = textBox1.Text;
  Form2.Show();
}



希望这可以帮助! ;-)



Hope this helps! ;-)


嗨..

首先,您将2种形式设置为PUBLIC.
和LABEL也一样.

为Form1创建对象.

例如:
-
Form2Label.Text = ObjForm1.Form1label.Text








问候,
莎拉
Hi..

first u set the 2 forms to PUBLIC.
and same as the LABEL also.

Create the Object for Form1.

Ex:
--
Form2Label.Text = ObjForm1.Form1label.Text








Regards,
Saran


这篇关于如何通过其他形式设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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