Click here to Skip to main content
12,298,927 members (49,586 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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:
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:
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:
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 29-Nov-12 1:57am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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();
        }
  Permalink  
v2
Comments
Member 9598596 29-Nov-12 8:06am
   
But PS() is not in Form2.
Krunal R 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100