Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

HI,

 

I've been working on control arrays and have a test form that has the following code:

 

Private Sub frmControlArrayTester_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       'Draw Array of Text Boxes
       '
       Dim TextBoxLocationFromLeft As Double
       Dim TextBoxLocationFromTop As Double = 29

       Dim TB(9) As TextBox
       For x As Integer = 0 To 5
           TextBoxLocationFromLeft = (48 + (x * 32))
           TB(x) = New TextBox
           TB(x).Location = New System.Drawing.Point(TextBoxLocationFromLeft, TextBoxLocationFromTop)   '(x * 10, x * 10)
           TB(x).MaxLength = 2
           TB(x).AutoSize = False
           TB(x).BackColor = System.Drawing.SystemColors.Info
           TB(x).BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
           TB(x).Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
           TB(x).ForeColor = System.Drawing.Color.Blue
           TB(x).Name = "txtEnter"
           TB(x).Size = New System.Drawing.Size(24, 20)
           TB(x).TabIndex = x
           TB(x).Text = ""
           TB(x).WordWrap = False
           Me.ErrorProvider1.SetIconAlignment(TB(x), System.Windows.Forms.ErrorIconAlignment.TopRight)
           Me.ErrorProvider1.SetIconPadding(TB(x), -10)
           Me.Controls.Add(TB(x))
           [b]AddHandler TB.Click, AddressOf TextBoxArray_Click[/b]
       Next
End Sub

 

The line in bold is causing it to hang up. If I comment that line out there is no problem. Do you see anything wrong with this. Also I need three events setup for these textboxes: Click event, GotFocus event, and TextChanged event.

 

Is is possible to set up three events usint the above loop. If I put my cursor in the part "TB.Click" and remove the period the intellisense pops up and suggest button. Sorry but I'm a little confused about all this I guess. Your comments are very welcome

 

mark

Posted

You're right!

 

I don't know what I was thinking... The fact that that it was hanging up had me all messed up I guess.

 

I might add that when It DID hang, simply commenting it would not get it to compile... I would have to shut down and restart VS to get it to compile again once the error occurred.

 

Thank you so very much...

So my code now looks like this:

Private Sub frmControlArrayTester_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       'Draw Array of Text Boxes
       '
       Dim TextBoxLocationFromLeft As Double
       Dim TextBoxLocationFromTop As Double = 29

       Dim TB(5) As TextBox
       For x As Integer = 0 To 5
           TextBoxLocationFromLeft = (48 + (x * 32))
           TB(x) = New TextBox
           TB(x).Location = New System.Drawing.Point(TextBoxLocationFromLeft, TextBoxLocationFromTop)   '(x * 10, x * 10)
           TB(x).MaxLength = 2
           TB(x).AutoSize = False
           TB(x).BackColor = System.Drawing.SystemColors.Info
           TB(x).BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
           TB(x).Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
           TB(x).ForeColor = System.Drawing.Color.Blue
           TB(x).Name = "txtEnter"
           TB(x).Size = New System.Drawing.Size(24, 20)
           TB(x).TabIndex = x
           TB(x).Text = ""
           TB(x).WordWrap = False
           Me.ErrorProvider1.SetIconAlignment(TB(x), System.Windows.Forms.ErrorIconAlignment.TopRight)
           Me.ErrorProvider1.SetIconPadding(TB(x), -10)
           Me.Controls.Add(TB(x))
           AddHandler TB(x).Click, AddressOf TextBoxArray_Click
           AddHandler TB(x).TextChanged, AddressOf TextBoxArray_TextChanged
           AddHandler TB(x).GotFocus, AddressOf TextBoxArray_GotFocus

       Next
   End Sub

   Private Sub TextBoxArray_Click(ByVal sender As Object, ByVal e As System.EventArgs)
       MessageBox.Show(sender.Text)
   End Sub

   Private Sub TextBoxArray_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
       MessageBox.Show(sender.Text)
   End Sub
   Private Sub TextBoxArray_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
       MessageBox.Show(sender.Text)
End Sub

 

Is this workable using three events in the loop?

 

Mark

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...