D
Douglas E. Rasmusen
Copy and paste this into the code of a Windows form...
'Written by Douglas E. Rasmusen ([email protected])
'Create a form named Form1.
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim TextCounter As Integer
Private Sub Form1_Click(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Click
TextCounter += 1 'Increase the counter for identification purposes.
Dim txtText As New TextBox ' Declare a new TextBox.
Me.Controls.Add(txtText) ' Add the TextBox to the form's Controls
collection.
With txtText
..Top = 20 * TextCounter 'Offset the TextBox vertically.
..Left = 20 * TextCounter 'Offset the TextBox horizontally.
..Width = 50 'Set the TextBox's width.
..Visible = True 'Make it seen by the user.
..Tag = Str(TextCounter) 'The Tag property acts as the old "Index" property
(e.g. TextCounter = 4, Tag = " 4").
'This method allows for multidimentional control arrays
'limited only by the length of the Tag property.
'Example: txtText.Tag = " 1024 23 99" could represent a TextBox on the
1024th row,
'the 23rd column, and 99 pages deep.
..Text = txtText.Tag 'Display the Tag property to the user.
AddHandler txtText.DoubleClick, AddressOf txtText_DoubleClick 'Add a
DoubleClick event.
End With
End Sub
Private Sub txtText_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim answer As String 'Declare a variable for the user's input.
MessageBox.Show("You seleced TextBox Number" & sender.tag) 'Tells the user
which TextBox was selected.
answer = InputBox("Which TextBox would you like to destroy? Enter 1 through"
& Str(TextCounter) & " or ALL") 'There is no error checking here.
If answer = "ALL" Then
For Each txtText As TextBox In Me.Controls
Me.Controls.Remove(txtText)
Next
Else
For Each txtText As TextBox In Me.Controls 'Loop through all the TextBoxes
on the form.
MessageBox.Show("Checking txtText number" & txtText.Tag) 'Shows user which
TextBox is currently being examined.
If txtText.Tag = " " & answer Then 'Note the additional space before the
answer.
Me.Controls.Remove(txtText) 'Removes the selected control.
End If
Next
End If
End Sub
End Class
It works, but if you try the ALL option, it only removes the odd numbered
TextBoxes?!?!?! Any ideas or coments?
'Written by Douglas E. Rasmusen ([email protected])
'Create a form named Form1.
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Dim TextCounter As Integer
Private Sub Form1_Click(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Click
TextCounter += 1 'Increase the counter for identification purposes.
Dim txtText As New TextBox ' Declare a new TextBox.
Me.Controls.Add(txtText) ' Add the TextBox to the form's Controls
collection.
With txtText
..Top = 20 * TextCounter 'Offset the TextBox vertically.
..Left = 20 * TextCounter 'Offset the TextBox horizontally.
..Width = 50 'Set the TextBox's width.
..Visible = True 'Make it seen by the user.
..Tag = Str(TextCounter) 'The Tag property acts as the old "Index" property
(e.g. TextCounter = 4, Tag = " 4").
'This method allows for multidimentional control arrays
'limited only by the length of the Tag property.
'Example: txtText.Tag = " 1024 23 99" could represent a TextBox on the
1024th row,
'the 23rd column, and 99 pages deep.
..Text = txtText.Tag 'Display the Tag property to the user.
AddHandler txtText.DoubleClick, AddressOf txtText_DoubleClick 'Add a
DoubleClick event.
End With
End Sub
Private Sub txtText_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim answer As String 'Declare a variable for the user's input.
MessageBox.Show("You seleced TextBox Number" & sender.tag) 'Tells the user
which TextBox was selected.
answer = InputBox("Which TextBox would you like to destroy? Enter 1 through"
& Str(TextCounter) & " or ALL") 'There is no error checking here.
If answer = "ALL" Then
For Each txtText As TextBox In Me.Controls
Me.Controls.Remove(txtText)
Next
Else
For Each txtText As TextBox In Me.Controls 'Loop through all the TextBoxes
on the form.
MessageBox.Show("Checking txtText number" & txtText.Tag) 'Shows user which
TextBox is currently being examined.
If txtText.Tag = " " & answer Then 'Note the additional space before the
answer.
Me.Controls.Remove(txtText) 'Removes the selected control.
End If
Next
End If
End Sub
End Class
It works, but if you try the ALL option, it only removes the odd numbered
TextBoxes?!?!?! Any ideas or coments?