Click here to Skip to main content
16,013,465 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have very basic question, but I don't find the solution.
I have MAIN PROGRAM (maybee this is not a good name) and two form.
In this MAIN PROGRAM I call Form2. With button in Form2 I call Form1. Now I want to call method PS of MAIN PROGRAM with button in Form1


MAIN PROGRAM:
C#
namespace Example.csproj
{
    public partial class SolidWorksMacro
    {

        public Form1 RWindow = new Form1();
        public Form2 BWindow = new Form2();
        

        public void Main()
        {
            BWindow.ShowDialog();
            
        }

        public void PS() 
        {
            MessageBox.Show("WORKING");
        }

        public SldWorks swApp;
    }
}


FORM2:
C#
namespace Example.csproj
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 frm = new Form1();
            frm.Show();
            this.Close();
            
        }
    }
}


FORM1:
C#
namespace Example.csproj
{
    public partial class Form1 : Form
    {
        

        public Form1()
        {
            
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //I tried to call method PS with this two below sentence, but I get error: No overload for method 'SolidWorksMacro' takes '0' arguments

            //SolidWorksMacro m_Macro = new SolidWorksMacro();
            //m_Macro.PS();
            
            this.Close();
        }
    }
}


Therefore which is the best/simple way to call method PS with button from Form1.
Posted

1 solution

Create the object of Form 2 and simply call the method..
SolidWorksMacro f = new SolidWorksMacro();
private void button1_Click(object sender, EventArgs e)
        {
          f.PS();
        }
 
Share this answer
 
v2
Comments
Member 9598596 29-Nov-12 8:06am    
But PS() is not in Form2.
[no name] 29-Nov-12 8:14am    
solution has been updated..
Member 9598596 29-Nov-12 8:19am    
Look up in code. I tried to do this befor but then I get error:
No overload for method 'SolidWorksMacro' takes '0' arguments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900