我正在尝试调整打开窗口的大小,因为在 Wonderware Application Server 中似乎没有办法做到这一点,我认为 .Net 功能可能会起作用。我在 Wonderware Application Server 中使用了下面的 System.Windows.Forms.MessageBox.Show 脚本和一个按钮激活脚本。是否有类似的功能可以简单地更改当前活动窗口的高度和宽度?
消息框只是 Wonderware Application Server 应用程序可以访问其 QuickScript.NET 脚本中的某些 System.Windows.Forms 函数的一个示例。Windows 窗体库 (system.windows.forms.dll) 已导入 Wonderware Application Server 应用程序。该脚本将在打开的窗口上运行,我想调整它的大小,但我无法让 .Net 大小函数在 QuickScript.NET 中工作。
找到这个系统平台 DLL 示例http://www.plctalk.net/qanda/showthread.php?t=114301但 Visual Studio 有 20 个不同的类库模板。如果我尝试使用类库 (.Net Framework) - C# 模板,我会得到一个 dll 并可以将其导入系统平台,然后我可以在函数浏览器中找到该函数,但是当脚本运行时在运行时没有任何反应,我得到了这个SMC 日志中的错误:脚本执行异常。消息:非静态方法需要一个目标。
演示 - Visual Studio 2019 和类库 (.Net Framework) - C# 模板代码:
namespace ClassLibraryDemo
{
public class DemoClass
{
public int GetAdd(int a, int b)
{
return a + b;
}
}
}
演示 - 系统平台按钮脚本 - 对于此演示代码,它现在可以与添加的 cls = 新行一起使用。
dim cls as ClassLibraryDemo.DemoClass;
cls = new ClassLibraryDemo.DemoClass();
Me.°Test = cls.GetAdd(Me.°Test,3);
不幸的是,我需要的调整大小代码仍然有非静态错误,并且它已经有对象等于新行。
ResizableForm - Visual Studio 2019 和类库 (.Net Framework) - C# 模板代码:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ClassLibraryROB4
{
public class ResizableForm
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public Form GetCurrentWindow()
{
IntPtr activeWindowHandle = GetForegroundWindow();
Form f = Control.FromHandle(activeWindowHandle) as Form;
return f;
}
}
}
ResizableForm - 系统平台按钮脚本。现在使用 Try-Catch
Try
Dim myLib As ClassLibraryROB4.ResizableForm;
Dim myGfc As System.Windows.Forms.Form;
myLib = new ClassLibraryROB4.ResizableForm();
myGfc = myLib.GetCurrentWindow();
myGfc.Width = 10;
myGfc.Height = 10;
catch LogError(error); endtry;
SMC 错误 - Try-Catch
A900.Faceplate1_Control.BUTTON2: System.Reflection.TargetException: Non-static method requires a target.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ArchestrA.QuickScript.EvaluateFunction.Evaluate(IReferenceManagerRuntime rmr)
at ArchestrA.QuickScript.RunExpressionStatement.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunStatements.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunTryCatch.Run(RuntimeContext context)