从另一种形式的另一个复选框中获取并设置复选框的选中状态 [英] get and set the checked state of checkbox from another checkbox in another form

查看:76
本文介绍了从另一种形式的另一个复选框中获取并设置复选框的选中状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我想选中该复选框,如果未选中另一种形式的复选框..
如果未选中checkbox1,则必须选中其他形式的check ..

我的代码是...

在第二个复选框的checkedchanged事件中...


hi all...

i want to check the checkbox if the checkbox in another form is unchecked..
if checkbox1 is unchecked then the checkbox of other form must be checked..

my code is...

in checkedchanged event of 2nd checkbox...


Form1 f1 = new Form1();

bool chk = false;

if (!checkBox2.Checked)
    chk = true;
f1.checkBox1.Checked = chk;


这里checkbox2是第二种形式的复选框...
它不起作用...
谁能帮我...

在此先感谢...


here checkbox2 is checkbox of 2nd form...
its not working...
can anyone help me...

Thanks in Advance...

推荐答案

一个受欢迎的问题.表单协作的最可靠方法是在表单类中实现某些接口.
请查看我过去的答案,其他答案和讨论:
如何在列表框之间复制所有项目两种形式 [ ^ ].

—SA
A popular question. The most robust approach to form collaboration is implementing some interface in the form class.
Please see my past answer, other answers and the discussion:
How to copy all the items between listboxes in two forms[^].

—SA


单击按钮或其他东西以打开Form1时,将以下代码放置在该位置.

When you click the button or something to open the Form1, place following code on that location.

Form1 f1 = new Form1();
f1.checkBox1.Checked = !checkBox2.Checked;
f1.Show();



这足以满足您的需求.

当前,每次您选中/取消选中复选框时,都会创建一个新对象,并且我确定您也必须在显示该表单的地方创建一个新对象.


如果表单已经打开,或者您根本不希望打开表单;然后将您的表单Form1 f1 = new Form1();声明放在类的顶部,以获取表单的单个对象.



This is enough to do what you want.

Currently you create a new object everytime you check/uncheck the check box, and I am sure you must be creating a new object where you show the form too.


If form is already open or you don''t want the form to open at all; then put your declaration of form Form1 f1 = new Form1(); at the top of class to get the single object of the form.


这篇关于从另一种形式的另一个复选框中获取并设置复选框的选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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