Results 1 to 8 of 8

Thread: Runtime Array of Textbox Problem.

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    50

    Runtime Array of Textbox Problem.

    Ok so i am currently working on a magic square game and basically my form creates an 2d array, dimensions make by user(ex:2 by 2), then the form creates the number of textboxes(Ex:4) and i need to get the values in runtime to check if it is a magic square. Now i know this has something to do with addhandler so ill post my code and any help would be greatly appreciated.

    Code:
    Dim MakeArr(dbltxt - 1, dbltxt - 1)
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If dbltxt <= 9 Then
                Dim introw As Integer = 52
                Dim intcol As Integer = 290
                For i As Integer = 0 To dbltxt - 1
                    intcol = 290
                    introw += 30
                    For j As Integer = 0 To dbltxt - 1
                        intcol += 40
                        MakeArr(i, j) = New TextBox
                        With MakeArr(i, j)
                            .BringToFront()
                            .Name = ("texbox" & i.ToString & j.ToString)
                            .Text = "0"
                            .Left = intcol
                            .Top = introw
                            .Width = 35
                            .Height = 25
                        End With
                        Me.Controls.Add(MakeArr(i, j))
                    Next
                Next
            Else
                MessageBox.Show("Sorry the Max amount of squares is 9")
            End If
        End Sub

  2. #2
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Re: Runtime Array of Textbox Problem.

    Take a look at this example

    Code:
    Private Sub ShowTheTime(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs)
               ' ----- Display the time in the text box, if it exists.
               Dim theTextBox As TextBox
    
               ' ----- Locate and update the text control.
               theTextBox = Me.Controls("TimeTextBox")
               If (theTextBox IsNot Nothing) Then
                  theTextBox.Text = Now.ToLongTimeString( )
               End If
            End Sub
    
            Private Sub Form1_Load(ByVal sender As Object, _
                  ByVal e As System.EventArgs) Handles Me.Load
               ' ----- Add controls at runtime.
               Dim dynamicText As TextBox = Nothing
               Dim dynamicButton As Button
    
               ' ----- Dynamically add a text box control to the form.
               dynamicText = New Windows.Forms.TextBox
               dynamicText.Name = "TimeTextBox"
               dynamicText.Location = New System.Drawing.Point(8, 8)
               dynamicText.Size = New System.Drawing.Size(232, 20)
               dynamicText.TabIndex = 0
               Me.Controls.Add(dynamicText)
    
               ' ----- Dynamically add a button control to the form.
               dynamicButton = New Windows.Forms.Button
               dynamicButton.Location = New System.Drawing.Point(144, 32)
               dynamicButton.Size = New System.Drawing.Size(99, 23)
               dynamicButton.Text = "Get Time"
               dynamicButton.UseVisualStyleBackColor = True
               dynamicButton.TabIndex = 1
               Me.Controls.Add(dynamicButton)
    
               ' ----- Connect the button to an event handler.
               AddHandler dynamicButton.Click, AddressOf ShowTheTime
            End Sub

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Runtime Array of Textbox Problem.

    how do you determine if a textbox is a magic square?

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    50

    Re: Runtime Array of Textbox Problem.

    if when you add all the textboxes together diagonally, across and down they all have the same total

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    50

    Re: Runtime Array of Textbox Problem.

    marius40, i do not think it works cause its a 2d array and the addhandler doesnt seem to accept array.textchanged...

  6. #6
    Hyperactive Member
    Join Date
    Oct 2008
    Location
    South Africa
    Posts
    395

    Re: Runtime Array of Textbox Problem.

    I wrote the same game, a while back, i used button's and not Textboxes. Then i placed random numbers on each button, when the user click's the button, it swaps with the next button. Textboxes seems to be tricky.... well for me it was. Try buttons'.

    The code i gave should work. You are trying to refer to the button as an array? This could be a problem.

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    50

    Re: Runtime Array of Textbox Problem.

    Thank you for that idea but unfortunately it requires textboxes

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    50

    Re: Runtime Array of Textbox Problem.

    still unresolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width