|
-
Feb 23rd, 2010, 01:35 PM
#1
Thread Starter
Member
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
-
Feb 23rd, 2010, 02:25 PM
#2
Hyperactive Member
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
-
Feb 23rd, 2010, 02:25 PM
#3
Re: Runtime Array of Textbox Problem.
how do you determine if a textbox is a magic square?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 23rd, 2010, 02:31 PM
#4
Thread Starter
Member
Re: Runtime Array of Textbox Problem.
if when you add all the textboxes together diagonally, across and down they all have the same total
-
Feb 23rd, 2010, 02:34 PM
#5
Thread Starter
Member
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...
-
Feb 23rd, 2010, 02:41 PM
#6
Hyperactive Member
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.
-
Feb 23rd, 2010, 02:49 PM
#7
Thread Starter
Member
Re: Runtime Array of Textbox Problem.
Thank you for that idea but unfortunately it requires textboxes
-
Feb 23rd, 2010, 03:28 PM
#8
Thread Starter
Member
Re: Runtime Array of Textbox Problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|