Quantcast
Viewing all articles
Browse latest Browse all 12583

Call parent method from child form

I want to call parent method from child form.

Here is example. In main method I call Form2 then I call Form1 with button. Then I want to call method PS which is in SolidWorcsMacro (this is parent).

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace Example.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            Form2 frm = new Form2();
            frm.ShowDialog();
        }

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

        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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();
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Example.csproj
{
    public partial class Form1 : Form
    {
        SolidWorksMacro m_Macro;

        public Form1(SolidWorksMacro macro)
        {
            m_Macro = macro;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_Macro.PS();
            this.Close();
        }
    }
}

I try a lot of things to do that this code will be work. With this code I get next error: Error 2 No overload for method 'Form1' takes '0' arguments C:\Users\David\Desktop\MACRO-JI\C#\Example_mod\SwMacro\Form2.cs 23 25 Example                                                                                                                                                  Please help me


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>