繁体   English   中英

在 Wonderware Application Server 中使用 .NET System.Windows.Forms 命令调整弹出窗口的大小

[英]Resize Popup with .NET System.Windows.Forms commands in Wonderware Application Server

我正在尝试调整打开的 window 的大小,因为在 Wonderware Application Server 中似乎没有办法做到这一点,我想也许 a.Net function 可能会起作用。 我在 Wonderware Application Server 中使用了下面的 System.Windows.Forms.MessageBox.Show 脚本和按钮激活脚本。 是否有类似的 function 可以简单地更改当前活动 window 的高度和宽度?

该消息框只是 Wonderware Application Server 应用程序可以访问其 QuickScript.NET 脚本中的一些 System.Windows.Forms 函数的示例。 将 Windows Forms 库(system.windows.forms.dll)导入到应用程序应用程序中该脚本将在打开的 window 上运行,我想调整它的大小,但我无法让 .Net 大小 function 在 QuickScript.NET 中工作。


Found this System Platform DLL example http://www.plctalk.net/qanda/showthread.php?t=114301 but Visual Studio has like 20 different Class Library templates. If I try the Class Library (.Net Framework) - C# template I get a dll and can import it into System Platform, I can then find the function in the Function Browser but nothing happens in runtime when the script is run and I get this SMC 日志中的错误:脚本执行异常。消息:非静态方法需要一个目标。

演示 - Visual Studio 2019 和 Class 库(.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);

不幸的是,我需要的调整大小代码仍然有非静态错误,它已经有 object 等于新行。

ResizableForm - Visual Studio 2019 和 Class 库(.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)

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

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

教程可能对您有所帮助

链接用于调整 windows 表格的大小和定位

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

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

#1 - 创建你的脚本 Function 库。
我使用 C# 在 Visual Studio 中编写了非常基本的 Class 库,如下所示:

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
从 IDE 主 window : Galaxy -> Import -> Script Function Library...
然后 select the.dll 您从 #1 构建

#3 - ArchestrA 图形脚本
调用要调整大小的图形时,请确保在其上设置了显式的宽度/高度,然后您可以通过放置一些东西来触发如下脚本来动态调整它的大小:

Dim myLib As ResizableForm;
Dim myGfc As System.Windows.Forms.Form;

myLib = new ResizableForm();
myGfc = myLib.GetCurrentWindow();

myGfc.Width = #;
myGfc.Height = #;

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

编辑:我想我应该只提一下GetCurrentWindow()调用在 ArchestrA 图形中非常强大。 我使用另一个脚本来获取当前图形的句柄,并调用一些 .NET 函数将当前的 window 打印到动态选择的打印机上,这样我的客户就可以创建标签来粘贴。 基本上,如果您可以从此 function 获取表单句柄,则可以使用大多数 .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;

  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM