如何以其他形式传递bool [英] how to pass bool in other form

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

问题描述

我这里有3个表单,表单A是radioButton1,表单B有bool参数,表单C有复选框表单,

Hi, I have 3 form over here, the form A is radioButton1, formB has bool parameter and form C has checkbox form,

所以我试着调用formB at formC喜欢这个FormB obj = new FormB(a,b,c)但它错了。 

so I tried to call formB at formC like this FormB obj = new FormB (a,b,c) but it was wrong. 

我需要在表格A声明FormB,因为我需要从表格中重新发送数据但是当它在表单C中时,它点击按钮并出现表格B(组合框),这是从数据库中检索的数据。我是C#的新手。

I need to declare the FormB at Form A as I need to reterive data from Form A but when it is in Form C, it clicks the button and appear form B (combobox) which is the data retrieve from database. I am new to C#.

这是我的代码

here is my code

表单A

公共部分类FormA:表格

    {

        public FormA()

        {

            InitializeComponent();



            FormB obj1 = new FormB (radioButton1.Checked,radioButton2.Checked,radioButton3.Checked);



$




        }

public partial class FormA: Form
    {
        public FormA()
        {
            InitializeComponent();

            FormB obj1 = new FormB (radioButton1.Checked, radioButton2.Checked, radioButton3.Checked);




        }

表格B

表格C


     


       
public   FormC()


      ;  
{

        {


            
InitializeComponent();

            InitializeComponent();



          }



        
private
void < span style ="font-size:9.5pt; font-family:Consolas; color:black"> button2_Click( object
sender,
EventArgs e)


       
{

        {


          &NBSP;&NBSP;



         
if (checkBox1.Checked ==
true && checkBox2.Checked ==
true && checkBox3.Checked ==
true &&   
checkBox4.Checked ==
true

          if (checkBox1.Checked == true && checkBox2.Checked == true && checkBox3.Checked == true &&      checkBox4.Checked == true)


           
{

            {


               
FormB  sbo =

FormB  (); // 错误在这里(我不知道如何从其他形式调用它)

                FormB sbo = new FormB (); //the error is here (i dont know how to call it from other form)


               
如果 (sbo ==
null


               
{/ / span >

                {


                   
sbo.Parent =
this ;

                    sbo.Parent = this;


               
}

                }


               
sbo.Show( );

                sbo.Show();


               
this 。隐藏();


           
}

            }



         


}

推荐答案

只需传递所需的bool值,如

Just pass desired bool value like

FormB sbo = new FormB(true,false,true);

这里,a = true,b = false,c = true。
$


Here, a=true, b=false, c=true.

或者喜欢

FormB sbo = new FormB(checkBox1.Checked, checkBox2.Checked, checkBox3.Checked);

这里,checkBox.Checked有bool值。

Here, checkBox.Checked has bool value.

你需要确定FormB对a,b,c

You need to determine what FormB should have for a,b,c




如果你不想将bool从FormC传递到FormB,请将FormB中的构造函数重载为


If you don't want to pass bool from FormC to FormB overload the Constructor in FormB as

public partial class FormB : Form
    {
        public FormB()
        {
            InitializeComponent();
        }
        public FormB(bool a, bool b, bool c)
        {
            InitializeComponent();

            if (a == true)
            {


                //code here
            }
        }
    }








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

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