Object Instantiation

jccorner

Centurion
Joined
Jan 31, 2004
Messages
144
I am experiencing a 3-5 second lag on my textbox lost focus event. But only on the initial lost focus event. Here's what I'm doing:

My app includes about twenty different forms and so obviously I'm using addhandlers for my lostfocus and gotfocus of my textboxes and other controls. Well, I have created a VB module called cFields to store all my helper functions in. So in my cFields module I have code like this:

Code:
Public Sub TextField_LostFocus(...)
    dim t as textbox
    t = directcast(sender, textbox)
     if t.tag = "Name" then t.text = FirstUpper(t.text)
     if t.tag = "Num" and not isnumeric(t.text) then t.text = 0
     t.backcolor = system.drawing.white
End Sub

So in my form I have this code on the form load event:

Code:
Dim tFocus as New cFields

Private sub FormA_Load(...) Handles MyBase.Load
 for each ctl
      if ctl is typeof textbox
           t = directcast(ctl, textbox)
           addhandler t.lostfocus, addressof tfocus.Textfield_LostFocus
      endif
next
End Sub

Now the code works, but my problem is this. When the form loads and finally shows, the first textbox has focus. Now if I simply try to tab out of it, the program pauses for 3-5 seconds and then gives focus to the next control. And it only happens when the form is initially loaded. After that, I can fly through all of the textboxes without the lag. So, my question is this, is the lag (or delay, whatever you want to call it) being caused because on the first lostfocus event call, it is instantiating cFields (which has now grown to over 5000 lines of code including about 10 - 15 helper functions). How can I get cFields to be created on the form load so the user doesn't run into this lag?? I've also tried this:

Code:
Dim tFocus as cFields

Private sub FormA_Load(...) Handles MyBase.Load
  tFocus = new cFields

 for each ctl
      if ctl is typeof textbox
           t = directcast(ctl, textbox)
           addhandler t.lostfocus, addressof tfocus.Textfield_LostFocus
      endif
next
End Sub

But I still get the delay. If anyone can help, I'd be greatly appreciative.
 
Back
Top