Calling methods on one form from another

defunktlemon

Member
Joined
Jan 24, 2013
Messages
6
Location
Reading, England
Programming Experience
Beginner
Hi All.
I have a program which when a button is clicked on Form1 it runs a vision system operation on an image in a window on a Form1. There are also other buttons on the Form1 which can change things like threshold levels so the inspection can be run again with different settings. It all works fine but I want to change it to remove the buttons from Form1 so that when the user clicks on a button on Form1 it opens up another form, Form2, and all the buttons which were on Form1 are now on Form2 and the image analysis should run on Form1 when the buttons are used on Form2.
I have taken over all the code from Form1 to Form2 and I'm trying to make this happen by creating a new oject on Form1 which calls a method on Form2 which contains the code which was in Form1 and called when the button was clicked on Form1 - not working!!
I have a constructor in Form2 but I think I have become monumentally confused.

This was the code which was on Form1 when the inspection button was clicked.
C#:
        private void cmdInspectOnce_Click(object sender, EventArgs e)
        {
            iReturn = VisionSystem.InvModeSet(IpeEngCtrlLib.I_MODE.I_EXE_MODE_ONCE);
            if (_imgEngines!=null && _imgEngines[0]!=null)
            _imgEngines[0].cmdInspectOnce();//InvModeSet(IpeEngCtrlLib.I_MODE.I_EXE_MODE_ONCE);
        }

 

antpower

Member
Joined
Oct 28, 2014
Messages
5
Programming Experience
3-5
So if i understand correctly, you want to have the ability to put those buttons on another form?

If so, this can be done using delegates. This way you call a method from form1 when pressing a button in form2.
 

defunktlemon

Member
Joined
Jan 24, 2013
Messages
6
Location
Reading, England
Programming Experience
Beginner
Ok. Then I can have an operation run on form1 and return the string and integers values back to form2 to be displayed in text boxes?
 
Top Bottom