如何发送任何Checkbox的文本在form2中检查到form1中的checkedListBox [英] How to send text of any Checkbox is checked in form2 to checkedListBox in form1

查看:54
本文介绍了如何发送任何Checkbox的文本在form2中检查到form1中的checkedListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只知道set checkListBox modifier = internal。

I just know set checkListBox modifier = internal.
and

Form1 fm1 = new Form1();
fm1.checkListBox1.Text = this.checkBox1.Text



它不是工作。

任何人都可以建议我这个想法。

见下图。

http://terzasek.zhotspot.com/image/10152389_778170718888436_3719562139504542058_n.jpg [ ^ ]

推荐答案

不,它不会。

这部分是因为当你这样做时:

No, it won't.
That's partly because when you do this:
Form1 fm1 = new Form1();

它创建了一个新的表格实例,而不是访问正在显示的实例。

它是有点像汽车:如果你把你的手机放在汽车的手套箱里,然后买一个新手机 - 你希望在新的汽车手套箱里找到你的手机吗?


您需要访问现有的Form1实例,而不是创建一个新实例。

但是...更好的方法是让现有实例为您完成...



根据表格之间的关系,看看这些:

在两种表格之间传递信息,第1部分:父母对儿童 [ ^ ]

在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]

在两个表格之间转移信息,第3部分:孩子对孩子 [ ^ ]



从名称来看,你可能想要第2部分。

It creates a new instance of teh form, not accesses the instance that is displaying.
It's a bit like cars: if you put your mobile phone in the glove box of your car, then buy a new one - would you expect to find your mobile in the new car glove box?

You need to access the existing instance of Form1, not create a new one.
But...the better way is to get the existing instance to do it for you...

Depending on the relationship between the forms, have a look at these:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]

Judging from the names, you probably want part 2.


我能想到的最简单的方法如下:



将Form2调用为对话框(使用ShowDialog())并创建一个公共变量你的Form2将保存你想要在表单之间传输的数据(在你的情况下是一个bool [])然后在Form1中使用该变量然后你想要。
The easiest way I can think of is the following:

Call Form2 as a dialog(with ShowDialog())and make a public variable in your Form2 which will hold the data you want to transfer between forms(which in your case is a bool[]) then use that variable back in Form1 however you want.


这篇关于如何发送任何Checkbox的文本在form2中检查到form1中的checkedListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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