以编程方式控制其他窗口控件 [英] Control other windows controls programatically

查看:51
本文介绍了以编程方式控制其他窗口控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!,$


我正在尝试从当前窗口访问另一个窗口,并设法完成所有工作,例如启动后台工作那个窗口等等。


不幸的是,我遇到了问题,我通常使用这一行:

 Window2 frm = new Window2(); 

我已完成以下操作:

 public MainWindow()
{
InitializeComponent();

MessageBox.Show(" Check 1");
Window2 frm = new Window2();
MessageBox.Show(" Check 2");
}

该行给出了以下错误:

调用目标抛出了异常。




导致此问题的原因是什么?

请帮助

解决方案

嗨Zuher Lait < span class ="x_x_t-marker"> h,


根据您的描述和相关代码,我创建了一个简单的演示,如下所示,效果很好。您能否提供更多信息,例如通过OneDrive竞争简单的演示,这可以重现我的问题,解决问题将是有益的


注意:请在上传样本之前删除隐私信息。

 public Window12()
{

InitializeComponent();
MessageBox.Show(" Check 1");
Window2 frm = new Window2();
frm.Tb1.Text =" Window12" ;;
frm.Show();
MessageBox.Show(" Check 2");
}

祝你好运,


张龙


Hi everyone!,

I'm trying to accessing another window from my current window and manage to do all the stuff like starting a backgroundworker in that window, etc.

Unfortunately, I'm having a problem, I usually use this line:

Window2 frm = new Window2();

I've done the following:

public MainWindow()
        {
            InitializeComponent();

            MessageBox.Show("Check 1");
            Window2 frm = new Window2();
            MessageBox.Show("Check 2");
        }

That line gives me the following error:

Exception has been thrown by the target of an invocation.


What is the cause of this problem ?
help please

解决方案

Hi Zuher Laith,

According to your description and related code, I create a simple demo as below, which works well. Could you please provide a bit more information, such as a compete simple demo via OneDrive, which could reproduce the issue on my side, it will be beneficial to resolve the issue.

Note: Please remove privacy information before you upload your sample.

public Window12()
{

   InitializeComponent();
   MessageBox.Show("Check 1");
   Window2 frm = new Window2();
   frm.Tb1.Text = "Window12";
   frm.Show();
   MessageBox.Show("Check 2");
}

Best regards,

Zhanglong


这篇关于以编程方式控制其他窗口控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆