Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
Course Name Date Time Duration Type Location
Selenium 4 + Cucumber BDD 27th November 2019 7.00 AM IST to 8:30 AM IST 40 Days WeekDays Online

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Thursday, September 2, 2010

DotnetFactory Object - Creating .Net Forms Using QTP

'###############################################
'           DotNetFactory Object 
'###############################################

'Purpose - To create an instance of a .NET object, and access its methods and properties.
'      We can create forms where the user can interact with them and give some input in run time
 
 Set MainForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
 Set TextField = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
 Set Button = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
 Set objPosition = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
 
 'Assign Text Field Details
 objPosition.X = 100
 objPosition.Y = 100
 TextField.Location = objPosition
 TextField.Width = 100
 
 'Assign Button Details
 objPosition.X = 100
 objPosition.Y = 130
 Button.Location = objPosition
 Button.Text = "Close"
 
 'Add Text Field and Button to Main Form
 MainForm.Controls.Add TextField
 MainForm.Controls.Add Button
 MainForm.CancelButton = Button
 
 'Show Form
 MainForm.ShowDialog
 
 Msgbox TextField.Text
  
 Set TextField = Nothing
 Set Button = Nothing
 Set objPosition = Nothing
 Set MainForm = Nothing

1 comment :

  1. Hi Sudhakar

    thanks for sharing this info.

    I would like to know, how do i create an instance of an existing Application window - for Ex: Outlook - Meeting Form.

    Thanks for your reply in advance

    ReplyDelete