views:

39

answers:

1

Hi I'm trying to reuse some code i was pointed to earlier to run a 3rd party .exe inside of a my winform

the code i was given was

via Mr. Greg Young

 public class Native {
        [DllImport("user32.dll", SetLastError = true)]
        private static extern uint SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        public static void LoadProcessInControl(string _Process, Control _Control)
        {
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(_Process);
            p.WaitForInputIdle();
            Native.SetParent(p.MainWindowHandle, _Control.Handle);
        }
    }

where it execution would be

public partial class Form1 : Form {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadProcessInControl("notepad.exe", this.splitContainer1.Panel1);
            LoadProcessInControl("notepad.exe", this.splitContainer1.Panel2);
        }
    }

However I keep getting "The name 'LoadProcessInControl' does not exist in the current context"

Scope of classes is still a weak point in my programing knowledge and I'm hoping to understand it a little better.

Ive tried switching the class to public and removing static from the method (load procincontrol) but I'm not getting anywhere)

Thanks for your help

+3  A: 

In the Form1_Load() function, try refering to Native.LoadProcessInControl() instead of just LoadProcessInControl().

Stephen C. Steel
that gets me "An object reference is required for the non-static field, method, or property 'Perls.Form1.Native.LoadProcessInControl(string, System.Windows.Forms.Control)' "
Crash893
nevermind it works ( i removed static from the OC and forgot to put it back) Thanks
Crash893