WinForms raise event from another Form

后端 未结 2 798
北荒
北荒 2021-01-03 16:24

I have a main form named: MainForm and a child form named: ChildForm I want to fill ChildForm\'s textboxes and in MainForm_ButtonClick i want to fire ChildForm_ButtonClick e

2条回答
  •  迷失自我
    2021-01-03 17:19

    To access a textbox in another form:

    1. Set Modifier property of the the textbox to public in child form.

    2. In main form, access the textbox by an object of the child form.

      Eg:

      obj.txtBox.Text="MyValue";
      

    To access an event in another form:

    1. Set the event handling function to public.

    2. Invoke the function by passing null as parameters by the object of the form.

      Eg:

      obj.MyButton_Click(null, null);
      

提交回复
热议问题