I'm trying to resize an open window and as there seems to be no way to do this in Wonderware Application Server I thought maybe a .Net function may work. I've used the System.Windows.Forms.MessageBox.Show script below in the Wonderware Application Server with a button activation script. Is there a similar function to simple change the Hight and Width of the currently active window?
The message box is just an example that the Wonderware Application Server application can access some System.Windows.Forms functions in it's QuickScript.NET scripting. The Windows Forms library (system.windows.forms.dll) was imported into the Wonderware Application Server application. The script would be running on an open window and I'd like to resize it but I can't get the .Net size function to work in 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 error in the SMC log: Script execution exception.Message: Non-static method requires a target..
Demo - Visual Studio 2019 and the Class Library (.Net Framework) - C# template code:
namespace ClassLibraryDemo
{
public class DemoClass
{
public int GetAdd(int a, int b)
{
return a + b;
}
}
}
Demo - System Platform Button Script - For this demo code it now works with the cls = new line added.
dim cls as ClassLibraryDemo.DemoClass;
cls = new ClassLibraryDemo.DemoClass();
Me.°Test = cls.GetAdd(Me.°Test,3);
Unfortunately, the resize code that I need still has the Non-static error and it already has the object equals new line.
ResizableForm - Visual Studio 2019 and the Class Library (.Net Framework) - C# template code:
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 - System Platform Button Script. Now with 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 Error - 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)