FartNocker Posted December 29, 2003 Posted December 29, 2003 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 Quote
*Gurus* divil Posted December 29, 2003 *Gurus* Posted December 29, 2003 TB has no events. What you mean is TB(x).Click. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
FartNocker Posted December 29, 2003 Author Posted December 29, 2003 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 Quote
FartNocker Posted December 30, 2003 Author Posted December 30, 2003 In the above code that shows the three event handlers, in the TextChanged event handler, How can I get the index of sender? Mark Quote
Administrators PlausiblyDamp Posted December 30, 2003 Administrators Posted December 30, 2003 something similar to Dim i As Integer i = System.Array.IndexOf(TB, sender) might do it (haven't tested it) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
FartNocker Posted December 31, 2003 Author Posted December 31, 2003 Perfect PlausiblyDamp You are excellent! I knew it would be one simple little line of code. Thanks for the lesson Mark Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.