I am not trying to confuse anyone. I did not delete the text box at any
time. For the sake of argument, I tried it again exactly as I did it the
first time. I started a new project then added a button1 and text box and the
public variable "eventtracker as an arraylist. This time it seemed to track
all the events ok. However, the textbox1.LostFocus event fired before the
textbox1.Validating event which is contrary to the M'soft's documentation
which says the validating event fires before the lostfocus event. This
eratic behavior of the control events makes if difficult and seems to be
inexcusable on Microsoft's part. Here is the complete project code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub _
InitializeComponent ()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(184, 146)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(76, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(184, 62)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(84, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 262)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public eventtracker As ArrayList = New ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.GotFocus
eventtracker.Add("textbox1 - gotfocus")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.TextChanged
eventtracker.Add("textbox1 - TextChanged")
End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.Leave
eventtracker.Add("textbox1 - Leave")
End Sub
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.LostFocus
eventtracker.Add("textbox1 - Lostfocus")
End Sub
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
eventtracker.Add("textbox1 - Validating")
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.Click
eventtracker.Add("button1 - Click")
End Sub
Private Sub Button1_GotFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.GotFocus
eventtracker.Add("button1 - gotfocus")
End Sub
Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.LostFocus
eventtracker.Add("button1 - lostfocus")
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Click
Dim s As String
Dim i As Integer
While i < eventtracker.Count
s = s & eventtracker(i).ToString & vbLf
i = i + 1
End While
MsgBox(s, MsgBoxStyle.OKOnly, "Event Track...")
End Sub
End Class
"Cor Ligthert" wrote:
Dennis,
Do you see that in this code is your code is almost what Ken wrote.
However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.
So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.
Are you trying to confuse us
:-)
no problem I hope this helps
Cor