DotNetFactory interface functions (6) – Create GUI Form
Parent page: Service Functions – DotNetFactory (QTP, VBScript)
Creating .NET objects from VBScript/QTP
You can create a basic Form and assign required properties within one line by calling the function below. The function has one mandatory parameter (which though is initialized by default if empty) and a set of optional parameters provided in the Dictionary object.
Currently supported optional parameters:
Form Width and Height.
Form Coordinates – Left, Top.
- p.locksize – Specify whether the Form is resizable by the user.
- p.lockview – Specify whether the Form is maximizable/minimizable.
- p.startpos – Specify start postion (CenterScreen or Manual).
Note 1. If start position is not set to Manual window location won’t be affected by your custom Left/Top settings. It will be set in accordance with the current default window position provided by the Operating System.
Note 2. You may code as many optional parameters as required. Just follow the established syntax and keep in mind that parameter index for Dictionary must be unique – otherwise it will overwrite the previous parameter.
References
For the complete .NET Form Class reference please visit:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form(VS.80).aspx
Used resources
Service Functions – String (QTP, VBScript)
Implementing optional and default parameters
Create Form
Public Function CreateForm(ByVal sTitle, ByVal objParameter) Dim intWidth, intHeight, intLeft, intTop Dim boolLockSize, boolLockView, sStartPosition Dim FormSize Dim objForm, objStartPos 'Verify parameters If TypeName (objParameter) <> "Dictionary" Then Set objParameter = CreateObject("Scripting.Dictionary") End If If sTitle = "" Then sTitle = "Form" intWidth = InitLong(objParameter.Item("p.width"), 500) intHeight = InitLong(objParameter.Item("p.height"), 300) intLeft = InitLong(objParameter.Item("p.left"), 100) intTop = InitLong(objParameter.Item("p.top"), 100) boolLockSize = InitBool(objParameter.Item("p.locksize"), TRUE) boolLockView = InitBool(objParameter.Item("p.lockview"), FALSE) sStartPosition = UCase(objParameter.Item("p.startpos")) Set objForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms") Set objStartPos = DotNetFactory.CreateInstance("System.Windows.Forms.FormStartPosition","System.Windows.Forms") objForm.Text = sTitle Select Case sStartPosition Case "CENTERSCREEN" objForm.StartPosition = objStartPos.CenterScreen Case "MANUAL" objForm.StartPosition = objStartPos.Manual Case Else objForm.StartPosition = objStartPos.WindowsDefaultLocation End Select objForm.Width = intWidth objForm.Height = intHeight objForm.Left = intLeft objForm.Top = intTop If boolLockSize Then Set FormSize = objForm.Size Set objForm.MinimumSize = FormSize Set objForm.MaximumSize = FormSize End If If boolLockView Then objForm.MaximizeBox = FALSE objForm.MinimizeBox = FALSE End If Set objStartPos = Nothing Set CreateForm = objForm End Function
Example
Set objForm = CreateForm("Test Setup", AssociateParameters("p.startpos = CenterScreen, p.width = 400, p.height = 300, p.locksize = Yes, p.lockview = Yes"))