开发者

Winforms - Scope of class

开发者 https://www.devze.com 2022-12-13 08:25 出处:网络
Hi I\'m trying to reuse some code I was pointed to earlier to run a 3rd party .exe inside of a my winform

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.splitContaine开发者_高级运维r1.Panel1);
            LoadProcessInControl("notepad.exe", this.splitContainer1.Panel2);
        }
    }

However I keep getting error:

The name 'LoadProcessInControl' does not exist in the current context

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

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

Thanks for your help


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

0

精彩评论

暂无评论...
验证码 换一张
取 消