C#子窗体给父窗体传值

父窗体:

  private void menu_Frame_Click(object sender, EventArgs e)
        {
            FrameForm ff = new FrameForm();
            ff.ShowUpdate += new FrameForm.DisplayUpdateDelegate(SetCameraFrameRate);
            ff.Show();
        }

        public void SetCameraFrameRate(int rate)
        {
            gl_frame = rate;
            timer2.Interval = 1000 / gl_frame;
            status_Frame.Text = "帧率:" + rate.ToString() + "FPS";
        }

子窗体:

  public delegate void DisplayUpdateDelegate(int rate);
        //声明事件
        public event DisplayUpdateDelegate ShowUpdate;
        private void button1_Click(object sender, EventArgs e)
        {
            if (ShowUpdate != null)
            {
                ShowUpdate(int.Parse(textBox1.Text));
            }
            this.Close();
        }

1、观察帧率值的变化,当前是默认值

2、进入子窗体,传值为30


3、最后传完后的状态


猜你喜欢

转载自blog.csdn.net/omodao1/article/details/80704151