有没有办法知道是否已经创建了 IWin32Window? [英] Is there a way to know if there is a IWin32Window already created?

查看:39
本文介绍了有没有办法知道是否已经创建了 IWin32Window?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序与其他几个应用程序集成.在一种情况下,我收到以下异常:

I am trying to integrate my application with several others. In one case I am getting the following exception:

System.InvalidOperationException was unhandled by user code
Message=SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

这个例外是因为我想这样做:

This exception is because i am trying to do:

System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

而且我尝试集成的应用程序已经创建了一些 IWin32Window.

And the application I am trying to integrate with has already created some IWin32Window.

我四处搜索,我得到的是,如果已经有 IWin32Window,我基本上不应该尝试 SetCompatibleTextRenderingDefault(false).但是由于我的应用程序将集成到其他各种应用程序中,因此每种情况下的条件都会发生变化.

I have searched around and what I get is that I basically should not try to SetCompatibleTextRenderingDefault(false) if there is already a IWin32Window. But since my application is going to be integrated in various others the conditions in each case change.

现在我计划更改我的应用程序以接收参数,因此根据上下文我可以运行或不运行 SetCompatibleTextRenderingDefault(false).

For now I am planning to change my application to receive a parameter so depending on the context I could run the SetCompatibleTextRenderingDefault(false) or not.

但我想知道是否有一种方法可以验证在执行 SetCompatibleTextRenderingDefault(false) 之前是否已经创建了 IWin32Window.

But I would like, instead, to know if there is a way that I could verify if there is already a IWin32Window created before doing SetCompatibleTextRenderingDefault(false).

如果这是一个愚蠢的问题,我很抱歉,但我之前并没有真正使用 Winforms.

I am sorry if this is a dumb question but I haven't really worked much with Winforms before.

如果您能给我任何帮助,我将不胜感激.

I would appreciate any help you can give me.

更新

在阅读第一个答案和一些评论后,我想提一下我遇到这个问题的上下文相当复杂,我无法在这里完全解释.感谢您的反馈,我理解您的意思.

After reading the first answer and some of the comments, I want to mention that the context where I am having this problem is rather complex and I can not completely explain it here. I appreciate the feedback and I understand what you are saying.

我认为我添加的上下文误解了我的问题的精神,我知道错误发生的原因,并且我知道解决它和解决问题的方法.

I think the spirit of my question was misunderstood by the context I added, I know why the error is happening and I know ways to solve it and get a work around.

我只是想知道是否有办法知道是否已经创建了 IWin32Window?

I just would like to know if there is a way to know if there is an IWin32Window already created?

毕竟,异常的发生是因为 IWin32Window 已经创建,所以我想知道你怎么知道的.

After all, the exception is happening because the IWin32Window is already created, so I was wondering how can you know that.

再次感谢.

推荐答案

没有办法知道 IWin32Window 是否已经在我的上下文中创建(框架不提供它).

There is no way to know if a IWin32Window was already created in my context (the framework doesn't offer it).

唯一可能的解决方法是拥有您自己的继承自 Winforms Form 的自定义表单.这样您就可以在创建表单时获得.

The only possible work around, is having your own Custom Form that inherits from Winforms Form. That way you can get when the forms are being created.

我不能这样做,因为我的应用程序与许多其他应用程序集成在一起,我无法强制它们全部使用 Windows 窗体以外的其他应用程序.

I can not do that, because my app gets integrated with many other, and I could not force them all to use other than Windows Form.

通过设置:

System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

我们试图为要集成的应用程序节省一些时间,但是当我们开始出现此错误时,我们删除了代码,并确定它们应该是配置兼容性设置的代码.

We were trying to save some time to the applications we were integrating with, however when we started having this error we removed the code, and stablished they should be the ones to configure the compatibility settings.

这篇关于有没有办法知道是否已经创建了 IWin32Window?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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