我正在尝试调整一个打开的窗口的大小,但在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应用程序中。脚本将在一个打开的窗口上运行,我想调整它的大小,但我无法在QuickScript.NET中使用.Net大小函数。
找到了这个系统平台的DLL示例http://www.plctalk.net/qanda/showthread.php?t=114301,但Visual Studio有20个不同的类库模板。如果我尝试类库(.Net框架)- C#模板,我得到一个dll并可以将其导入系统平台,然后我可以在函数浏览器中找到该函数,但是当脚本运行时在运行时没有任何反应,并且我在SMC日志中得到这个错误: script execution exception.Message: Non-static method requires a target..
演示- Visual Studio2019和类库(.Net框架)- C#模板代码:
namespace ClassLibraryDemo
{
public class DemoClass
{
public int GetAdd(int a, int b)
{
return a + b;
}
}
}Demo - System Platform Button Script -对于这个演示代码,它现在可以使用cls =新添加的行。
dim cls as ClassLibraryDemo.DemoClass;
cls = new ClassLibraryDemo.DemoClass();
Me.°Test = cls.GetAdd(Me.°Test,3);不幸的是,我需要的调整大小的代码仍然有非静态错误,并且它已经有了等于新行的对象。
ResizableForm - Visual Studio2019和类库(.Net框架)- 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错误-尝试-捕获
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)发布于 2021-04-21 18:46:56
创建自定义表单并根据需要设置属性:
static CustomMsgBox MsgBox; static DialogResult result = DialogResult.No;
////////////////////////////////////////////////////////////////////////////////
public static DialogResult Show(string Text, string Caption, string btnOK, string btnCancel)
{
MsgBox = new CustomMsgBox();
MsgBox.label1.Text = Text;
MsgBox.button1.Text = btnOK;
MsgBox.button2.Text = btnCancel;
MsgBox.Text = Caption;
result = DialogResult.No;
MsgBox.ShowDialog();
return result;
}
////////////////////////////////////////////////////////////////////////////////
result = DialogResult.Yes; MsgBox.Close();此tutorial可能会对您有所帮助
和此link用于调整windows窗体的大小和定位
发布于 2021-04-23 02:09:34
如果您愿意尝试使用脚本函数库,您可以编写一个实用程序来使图形可扩展。
如果你搜索“Wonderware ArchestrA中的可扩展弹出窗口”,我从this site得到了原始教程,但看起来他们把教程移到了注册页面后面。
#1 -创建脚本函数库。
我使用C#在Visual Studio中编写了非常基本的类库,如下所示:
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;
}
}#2 -导入到ArchestrA
在集成开发环境主窗口中:Galaxy -> Import -> Script Function Library...
然后选择您从#1构建的.dll
#3 - ArchestrA图形脚本
当调用你想要调整大小的图形时,确保你在它上面设置了一个显式的宽度/高度,然后你可以通过放置一些东西来触发一个脚本来动态地调整它的大小,如下所示:
Dim myLib As ResizableForm;
Dim myGfc As System.Windows.Forms.Form;
myLib = new ResizableForm();
myGfc = myLib.GetCurrentWindow();
myGfc.Width = #;
myGfc.Height = #;...and,我想就是这样了。希望这能让你走得足够远,这样你就可以玩弄剩下的东西。我建议您阅读EverDyn站点的教程,以获得更好的示例/详细信息。
编辑:我想我应该提一下,在ArchestrA图形中,GetCurrentWindow()调用是非常强大的。我使用另一个脚本来获取当前图形的句柄,并调用一些.NET函数将当前窗口打印到动态选择的打印机上,这样我的客户机就可以创建粘贴标签。基本上,如果您可以从该函数获得表单句柄,就可以使用大多数.NET库按您所希望的方式对其进行操作。祝好运!
根据注释编辑代码:
try
dim formID as System.IntPtr;
dim currentForm as System.Windows.Forms.Form;
formID = ClassLibraryROB4.ResizableForm.GetForegroundWindow();
currentForm = System.Windows.Forms.Control.FromHandle(formID);
currentForm.Width = #;
currentForm.Height = #;
catch
LogError(error);
endtry;https://stackoverflow.com/questions/67187540
复制相似问题