How to pass flag from childform to parent?

前端 未结 2 1130
旧时难觅i
旧时难觅i 2021-01-28 03:50

i have problem with passing boolean flag from childform to parentform.

I know how to pass it from parentform to childform for example:

On mainform:



        
相关标签:
2条回答
  • 2021-01-28 04:05

    Just implement an internal or public property in your Camera form, and set this property within it.

    Something like this:

      Camera settings = new Camera(this.fullPath3,this.flag);
      settings.ShowDialog();
      if (settings.Flag) text2.text="OK!";
    
    0 讨论(0)
  • 2021-01-28 04:10

    Simple, Camera is a form so just add a public property to it.

    public class Camera : Form
    {
       private string _fullPath3;
       private bool flag;
        public Camera(string fullPath3)
        {
    
            InitializeComponent();
            _fullPath3 = fullPath3;
        }
    
        // set flag to something somewhere
        public bool Flag{ get{ return flag; } }
    
    }
    

    Now just:

    Camera settings = new Camera(this.fullPath3);
    settings.ShowDialog();
    if (settings.Flag) text2.text="OK!";
    

    remember that ShowDialog halts execution!

    0 讨论(0)
提交回复
热议问题