VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
properties of single contol in a control array set up in a class Posted by bloodybullfrog on 20 Nov 2008 at 6:45 AM
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.")

Report
Re: properties of single contol in a control array set up in a class Posted by seancampbell on 20 Nov 2008 at 8:28 PM
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.
Report
Re: properties of single contol in a control array set up in a class Posted by bloodybullfrog on 21 Nov 2008 at 7:04 AM
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


Report
Re: properties of single contol in a control array set up in a class Posted by seancampbell on 21 Nov 2008 at 7:37 AM
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.
Report
Re: properties of single contol in a control array set up in a class Posted by bloodybullfrog on 21 Nov 2008 at 10:08 AM
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)
Report
Re: properties of single contol in a control array set up in a class Posted by seancampbell on 21 Nov 2008 at 11:48 AM
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)

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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.