从另一个表单访问动态标签值 [英] get access of dynamic label value from another form

查看:64
本文介绍了从另一个表单访问动态标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Windows应用程序。这里有2个表单,名为form1,form2。

在表格1中我有树视图和标签。



treeview节点。在根节点下所有都是子节点,如下所示。



root

node1

node2
node3

如果我选择任何子节点,标签文本将成为选定的节点名称。如果我选​​择node0,则标签值将成为nodeo。到现在好了。





现在来自form2我想得到label的值。但它给了我空值。我在下面写了代码。



表格1 ctrls = new form1();

textbox1.text = ctrls.label.text;



它给了我空值。 PLZ帮助我,我是c#的新手,并试图学习。

I am developing a windows application. Here I have 2 forms, named form1,form2.
In form 1 I have a treeview and label.

treeview Nodes. under root node all are the child nodes as shown below.

root
node1
node2
node3
if I select any child node the label text will become as selected node name.Like if I select node0, the label value will become nodeo. upto now it is ok.


now from form2 I want to get the value of label.but it is giving me empty value. I wrote below code.

form 1 ctrls=new form1();
textbox1.text=ctrls.label.text;

it is giving me empty value. plz help me I am new to c# and trying to learn.

推荐答案

引用:

form 1 ctrls = new form1();

textbox1.text = ctrls.label.text;

form 1 ctrls=new form1();
textbox1.text=ctrls.label.text;



在这里你创建一个全新的 form1 (当然是空标签)而不是使用原始标签。如果对原始 form1 的引用可用,则使用它。另一方面,如果它不可用,那么在关闭 form1 之前修改你的代码以将这个值传递给第二个Form(例如它的构造函数)。


Here you are creating a fresh new form1 (featuring, of course, the empty label) instead of using the original one. If a reference to the original form1 is available then use it. On the other hand, if it is not available then modify your code for passing such value to the second Form (for instance to its constructor) before closing form1.


这篇关于从另一个表单访问动态标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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