Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

properties of single contol in a control array set up in a class

bloodybullfrogbloodybullfrog Posts: 3Member
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

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Could you give me more code to look at? Like, the whole code for the class object and what you have tryed so far? Maybe what the error messages where saying...

    Im on a business trip, i will check back in tomorrow evening when i get back to my hotel room.
  • bloodybullfrogbloodybullfrog Posts: 3Member
    Sure
    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


  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    O_O

    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.
  • bloodybullfrogbloodybullfrog Posts: 3Member
    i am using the whole code to set up Deal or No Deal. This is the only way i found in Vb.net to make a control array and so far most of it works well all cases have a different random integer and right now my problem is i need the first case (its a button control) i click to move to a different place on the form. I am not sure if i need to somehow remove it from the array (i think that is possible MSDN says so lol)
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    I am not sure why you want to do the Button array, but check this code out. I have created an Array of 27 (0-26) buttons and am able to click on one and return its column and row position based off the Tag number. It uses one function that is added to each button. Just create a windows for, and paste this code in (might need to save the Windows Designer code from your new form)

    [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]
Sign In or Register to comment.