Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

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