|
-
Feb 14th, 2007, 05:58 AM
#1
WithEvents
Dear All,
What is the use of with Events in VB
Dana
Please mark you thread resolved using the Thread Tools as shown
-
Feb 14th, 2007, 06:12 AM
#2
Re: WithEvents
It means that, the Object you are declaring with the WithEvents statement, has some Events and you want to work with those Event Procedures.
When you doubleclick a control, VB autometically writes the event procedures. But, for objects declared with WithEvents, you have to write the event procedures yourself.
Take a look at the following example written by Static.
VB Code:
Dim WithEvents HTML As HTMLDocument
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.google.com"
End Sub
Private Function HTML_ondragstart() As Boolean
HTML_ondragstart = False
End Function
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.Application) Then
Set HTML = WebBrowser1.Document
End If
End Sub
In the above example, HTML is an object and it has some events. But as it is not a control (VB will not write it autometically), and we don't have the source code.
So to trap the dragging Static has written the HTML_ondragstart event procedure manually.
So, whenever user drags a link, the drag event fires, and the code inside the event procedure will run.
More more reference see:
http://www.developer.com/net/vb/article.php/1541411
http://www.codeguru.com/columns/vb/article.php/c6557/
and your MSDN CDs.
-
Feb 14th, 2007, 08:26 AM
#3
Re: WithEvents
Typically I will use With Events if I'm dynamically creating controls so that I can code the controls event (usually the click event) once the control has been made.
-
Feb 14th, 2007, 09:56 AM
#4
Re: WithEvents
@Hack,
Isn't it easier to use a control array and add the first control at designtime (Index=0) and rest of the controls at runtime ?
-
Feb 14th, 2007, 01:34 PM
#5
Re: WithEvents
 Originally Posted by iPrank
@Hack,
Isn't it easier to use a control array and add the first control at designtime (Index=0) and rest of the controls at runtime ?
Yes...but not nearly as much fun!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|