1

我正在尝试调整打开窗口的大小,因为在 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)
4

2 回答 2

1

根据需要创建自定义表单并设置属性:

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();

教程可能对您有所帮助

还有这个用于调整窗口大小和定位的链接

于 2021-04-21T10:46:56.137 回答
0

如果您愿意涉足使用脚本函数库,您可以编写一个实用程序来使图形可扩展。

如果您搜索“Wonderware ArchestrA 中的可扩展弹出窗口”,我会从该站点获得原始教程,但看起来他们正在将教程移到注册页面后面。

#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 -从 IDE 主窗口导入 ArchestrAGalaxy -> 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 = #;

……我想就是这样。希望这能让你走得更远,你可以玩弄其余的东西。我建议您阅读 EverDyn 网站的教程以获得更好的示例/详细信息。

编辑:我想我应该只提一下GetCurrentWindow()ArchestrA 图形中的调用非常强大。我使用另一个脚本来获取当前图形的句柄,并调用一些 .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;

  
于 2021-04-22T18:09:33.897 回答