I have set up a control array by making a class and using clickhandlers. What i need to do, is when the user clicks a control, i need that control to change position. I tried setting it up the same way as the message box i set up (below) but it didnt work.
MessageBox.Show("you have picked " & CType(CType(sender, _ System.Windows.Forms.Button).Tag, String) & " dollars.")
Comments
Im on a business trip, i will check back in tomorrow evening when i get back to my hotel room.
Public Class buttonarray
Inherits System.Collections.CollectionBase
Private ReadOnly hostform As System.Windows.Forms.Form
Dim x, y, c, numselect, intnumber, rand(0 To 26) As Integer
Public Function AddNewButton() As System.Windows.Forms.Button
If c = 0 Then
For x = 1 To 26
start: Randomize()
intnumber = Int((26 * Rnd()) + 1)
For y = 1 To 26
If intnumber = rand(y) Then
GoTo start
End If
Next y
rand(x) = intnumber
Next x
c = c + 1
ElseIf c = 1 Then
End If
' Create a new instance of the Button class.
Dim aButton As New System.Windows.Forms.Button()
' Add the button to the collection's internal list.
Me.List.Add(aButton)
' Add the button to the controls collection of the form
' referenced by the HostForm field.
hostform.Controls.Add(aButton)
AddHandler aButton.Click, AddressOf ClickHandler
' Set intial properties for the button object.
If Count = 1 Or Count = 2 Or Count = 3 Or Count = 4 Or Count = 5 Or Count = 6 Or Count = 7 Then
aButton.Top = 150
aButton.Left = (Count * 75)
aButton.Tag = rand(Count)
aButton.Text = "Case " & Me.Count.ToString
If aButton.Tag = 1 Then
........
End If
Return aButton
AddHandler aButton.Click, AddressOf ClickHandler
ElseIf Count = 15 Or Count = 16 Or Count = 17 Or Count = 18 Or Count = 19 Or Count = 20 Or Count = 21 Then
aButton.Top = 200
aButton.Left = ((Count - 14) * 75)
aButton.Tag = rand(Count)
aButton.Text = "Case " & Me.Count.ToString
If aButton.Tag = 1 Then
........
End If
Return aButton
AddHandler aButton.Click, AddressOf ClickHandler
ElseIf Count = 22 Or Count = 23 Or Count = 24 Or Count = 25 Or Count = 26 Then
aButton.Top = 225
aButton.Left = ((Count - 21) * 75) + 75
aButton.Tag = rand(Count)
aButton.Text = "Case " & Me.Count.ToString
If aButton.Tag = 1 Then
.........
End If
Return aButton
End If
End Function
Public Sub New(ByVal host As System.Windows.Forms.Form)
hostform = host
Me.AddNewButton()
End Sub
Default Public ReadOnly Property Item(ByVal Index As Integer) As _
System.Windows.Forms.Button
Get
Return CType(Me.List.Item(Index), System.Windows.Forms.Button)
End Get
End Property
Public Sub ClickHandler(ByVal sender As Object, ByVal e As _
System.EventArgs)
If numselect = 0 Then
End If
MessageBox.Show("you have picked " & CType(CType(sender, _
System.Windows.Forms.Button).Tag, String) & " dollars.")
End Sub
End Class
What are you using this class to do? I am going to paste it into my developer studio and take a peak at the code, probably will post an edit on this once I have an idea on whats going on. When you let me know what your up to with this class I might have some suggestions for you in regards to how you wrote the code.
[code]
Public Class Form33
Inherits System.Windows.Forms.Form
'This is just a test program to see if I can
'come up with a different way of doing this button
'array BS without using a Class object
Dim Butts(26) As Windows.Forms.Button
Private Sub Form33_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim row As Integer
Dim col As Integer
For x As Integer = 0 To 26
Butts(x) = New Windows.Forms.Button
Butts(x).Tag = x
Butts(x).Text = "B" & x.ToString
row = Math.Floor(x / 9) + 1
col = (x Mod 9) + 1
Butts(x).Top = 2 + ((row - 1) * 32)
Butts(x).Left = 2 + ((col - 1) * 32)
Butts(x).Width = 32
Butts(x).Height = 32
Me.Controls.Add(Butts(x))
AddHandler Butts(x).Click, AddressOf ButtClick
Next x
End Sub
Sub ButtClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim T As String = CType(sender, System.Windows.Forms.Button).Tag
Dim Row As Integer = Math.Floor(CInt(T) / 9) + 1
Dim Col As Integer = (CInt(T) Mod 9) + 1
MsgBox("Row and Col derived from the Tag on " & CType(sender, System.Windows.Forms.Button).Text & " is " & Row & ", " & Col)
End Sub
End Class
[/code]