Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Button1 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set Button2 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set dResult = DotNetFactory.CreateInstance("System.Windows.Forms.DialogResult", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
With Pos
.X = 50
.Y = 100
End With
With Button1
.Text = "Close"
.Location = Pos
.DialogResult = dResult.Cancel
End With
With Pos
.X = 150
.Y = 100
End With
With Button2
.Text = "OK"
.Location = Pos
.DialogResult = dResult.OK
End With
With Form
.Controls.Add Button1
.Controls.Add Button2
.Text = "My Custom User Form"
.ShowDialog
End With
If Form.DialogResult = dResult.OK Then
msgbox "OK Button Pressed"
else
msgbox "Close Button Pressed"
End If
Set Form = Nothing
Set Button1 = Nothing
Set Button2 = Nothing
Set dResult = Nothing
Set Pos = Nothing
If click on OK then it will launch the following msgbox
If click on close button then it will through following msgbox
No comments:
Post a Comment