注册 登录
编程论坛 C# 论坛

为什么调用控件类没有引用

扫地大爷 发布于 2021-09-23 21:05, 892 次点击
程序代码:
public partial class UserControlOne : UserControl
    {
        private Class1 pmclass;
        private bool Open;
        
        public PowerMILL.Application TestMain; //PowerMILL.Application这是接口
        public UserControlOne(Class1 class1, bool open)
        {
            InitializeComponent();

            this.Open = open;
            if (open)
            {
                this.pmclass = class1;
            }
            else
            {
                try
                {

                    TestMain = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerMILL.Application") as PowerMILL.Application;
                }
                catch(Exception)
                {
                    MessageBox.Show("链接失败");
                }
            }
        }
        private void COM(string comstr)
        {
            if (Open)
            {
                pmclass.Services.InsertCommand(pmclass.Token, comstr);
                Pmevenlist();
            }
            else
            {
                MessageBox.Show(comstr);

                this.TestMain.DoCommand(comstr);
            }

        }




程序代码:
    [local]1[/local]public partial class TestMain : Window
    {
        public TestMain()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            UserControlOne app = new UserControlOne(null,false);
            gridOne.Children.Add(app);

        }
    }
}



[此贴子已经被作者于2021-9-23 21:16编辑过]

2 回复
#2
扫地大爷2021-09-23 21:10
[附件]
只有本站会员才能查看附件,请 登录
[/附件]

[此贴子已经被作者于2021-9-23 21:15编辑过]

#3
扫地大爷2021-09-23 21:14
只有本站会员才能查看附件,请 登录
1