如何检查是否已加载从DLL加载的WinFrom。

问题描述:

大家好,



我有一个DLL加载到第三方应用程序(AutoCAD)。加载后,我可以触发命令加载winforms以在AutoCAD中执行操作。



我的一个命令加载一个对话框。



我如何测试该对话框是否已经运行并且没有再次加载Winform并且只是将其激活/在所有其他应用程序之上?



在此先感谢。



Stephan

Hi Guys,

I have a DLL loaded into a 3rd Party application (AutoCAD). Once loaded i can trigger commands to load winforms to do things with in AutoCAD.

One of my commands loads a dialog.

How I Test if that Dialog is already running and not load the Winform again and just make it active / on top of all other applications?

Thanks in advance.

Stephan

嗨Stephan,





如果你想找到特定的表格已经打开或有效。以下内容可能会对您有所帮助。



Hi Stephan,


if you want to find particular form is already opened or active. i thing the following may help you.

List<MyForm> CurrentActiveForms = System.Windows.Forms.Application.OpenForms.OfType<MyForm>().ToList();
if(CurrentActiveForms.Count == 0)
{
	// No match form found !!!!
	// request a new form to open
	return;
}

// do your stuff here........
MyForm DesireForm = CurrentActiveForms.FirstOrDefault(I => I.MyCondition == myCondition);

Or

MyForm DesireForm = CurrentActiveForms[0];

if (DesireForm != null || DesireForm.IsDisposed == false)
{
    DesireForm.focus();
}