I know that this probably has been done by someone, but I want to learn how to do this using VB 2010 express. I cannot seem to get the numbers to stay in the text boxes that they are dropped in. The numbers always go to the last box (#81). What am I doing wrong. You might have to change some lines to get the numbers to display in the lables assigned for them - that's ok.
creating a SuDoKu puzzle generator
Public Class Form2
Inherits System.Windows.Forms.Form
Public boxes(8, 8) As TextBox
Public newbox As TextBox
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim groupBoxes() As GroupBox = Me.Controls.OfType(Of GroupBox).OrderBy(Function(g) g.Name).ToArray
Dim arrayIndex As Integer = 0
Dim rowStartIndex As Integer = 0
Dim rowCounter As Integer = 0
Dim colCounter As Integer = 0
For row As Integer = 0 To 8
For col As Integer = 0 To 8
'create a new textbox and set its properties
newbox = New TextBox
newbox.Size = New Drawing.Size(50, 30)
newbox.Location = New Point(5 + colCounter * 70, 20 + rowCounter * 20 * 2)
newbox.TextAlign = HorizontalAlignment.Center
newbox.Font = New Font("Tahoma", 18, FontStyle.Bold)
newbox.AllowDrop = True
newbox.Clear()
'connect it to a handler, save a reference to the array and add it to the form controls
'AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged
AddHandler newbox.DragEnter, AddressOf TextBox_DragEnter
AddHandler newbox.DragDrop, AddressOf TextBox_DragDrop
boxes(row, col) = newbox
Dim gb As GroupBox = groupBoxes(arrayIndex)
gb.Controls.Add(newbox)
colCounter += 1
If colCounter = 3 Then colCounter = 0 : arrayIndex += 1
If col = 8 Then arrayIndex = rowStartIndex
Next
rowCounter += 1
If rowCounter = 3 Then rowCounter = 0 : arrayIndex += 3
rowStartIndex = arrayIndex
Next
Label1.Text = IIf(Display = 1, "1", "A")
Label2.Text = IIf(Display = 1, "2", "B")
Label3.Text = IIf(Display = 1, "3", "C")
Label4.Text = IIf(Display = 1, "4", "D")
Label5.Text = IIf(Display = 1, "5", "E")
Label6.Text = IIf(Display = 1, "6", "F")
Label7.Text = IIf(Display = 1, "7", "G")
Label8.Text = IIf(Display = 1, "8", "H")
Label9.Text = IIf(Display = 1, "9", "I")
Label16.Text = IIf(Autocheck = False, "Off", "On")
Label16.ForeColor = IIf(Autocheck = False, Color.Black, Color.Red)
Label17.Text = Microsoft.VisualBasic.Switch(Difficulty = 0, "Easy", Difficulty = 1, "Medium", Difficulty = 2, "Hard")
Label17.ForeColor = Microsoft.VisualBasic.Switch(Difficulty = 0, Color.Green, Difficulty = 1, Color.Black, Difficulty = 2, Color.Red)
Label18.Text = Microsoft.VisualBasic.Switch(Display = 0, "Letters", Display = 1, "Numbers")
Label18.ForeColor = Microsoft.VisualBasic.Switch(Display = 0, Color.Red, Display = 1, Color.Black)
Label19.Text = IIf(Sounds = False, "Off", "On")
Label19.ForeColor = IIf(Sounds = False, Color.Black, Color.Red)
End Sub
Private Sub TextBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
newbox.Text = e.Data.GetData(DataFormats.Text)
End Sub
Private Sub SettingsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
Me.Hide()
SetFrm.ShowDialog()
End Sub
Private Sub Label1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Label1.DoDragDrop(Label1.Text, DragDropEffects.Copy)
End Sub
Private Sub Label2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseDown
Label2.DoDragDrop(Label2.Text, DragDropEffects.Copy)
End Sub
Private Sub Label3_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseDown
Label3.DoDragDrop(Label3.Text, DragDropEffects.Copy)
End Sub
Private Sub Label4_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label4.MouseDown
Label4.DoDragDrop(Label4.Text, DragDropEffects.Copy)
End Sub
Private Sub Label5_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label5.MouseDown
Label5.DoDragDrop(Label5.Text, DragDropEffects.Copy)
End Sub
Private Sub Label6_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label6.MouseDown
Label6.DoDragDrop(Label6.Text, DragDropEffects.Copy)
End Sub
Private Sub Label7_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label7.MouseDown
Label7.DoDragDrop(Label7.Text, DragDropEffects.Copy)
End Sub
Private Sub Label8_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label8.MouseDown
Label8.DoDragDrop(Label8.Text, DragDropEffects.Copy)
End Sub
Private Sub Label9_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label9.MouseDown
Label9.DoDragDrop(Label9.Text, DragDropEffects.Copy)
End Sub
End Class
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
major_lost 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
major_lost 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.