简体   繁体   English

Winforms-课程范围

[英]Winforms - Scope of class

Hi I'm trying to reuse some code I was pointed to earlier to run a 3rd party .exe inside of a my winform 嗨,我正在尝试重用我之前指出的一些代码,以便在我的winform中运行第三方.exe

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 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) 我尝试过将类切换为公共类,并从方法中删除静态方法(加载procincontrol),但我什么都没得到)

Thanks for your help 谢谢你的帮助

在Form1_Load()函数中,尝试引用Native.LoadProcessInControl()而不是仅引用LoadProcessInControl()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM