所以基本上我有一个程序可以让用户从常规圆桌,中轮和小轮中挑选,他们也可以输入他们想要的金额。我需要表单才能工作,以便所有表格(无论大小)都动态添加到表单中,但间距相等,为48px(2英尺)。下面的代码是我一直在努力的,但它变得混乱,我认为它不会考虑所有情况。
Public Class Form1
Dim intX As Integer
Dim intY As Integer
Public NumClicks As Integer
Public ArrayWatch As Integer
Public varArray() As String
Public Sub btnEnter_Click_1(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
Dim tblName As String
Dim x As Integer
Dim i As Integer
Dim tblCt As Integer
Dim paramHeight As Integer
Dim paramWidth As Integer
Dim intXIncrement As Integer
Dim intYIncrement As Integer
i = 0
If txtInput.Text = "" Then
MsgBox("Please enter an amount of tables.")
Else
tblCt = Integer.Parse(txtInput.Text)
End If
' Sets width and height of images based on selection
'Regular Tables.
If optRegRd.Checked = True Then
paramHeight = 120
paramWidth = 120
intX = 48
intY = 48
tblName = "regularRound.png"
If Not (IsNothing(varArray)) Then
If varArray(UBound(varArray)) = "regularRound.png" Then
intYIncrement = 160
intXIncrement = 160
ElseIf varArray(UBound(varArray)) = "mediumRound.png" Then
For x = 0 To 1
intXIncrement = 144
intYIncrement = 144
Next
intYIncrement = 48
intXIncrement = 48
ElseIf varArray(UBound(varArray)) = "smallRound.png" Then
intYIncrement = 48
intXIncrement = 48
End If
Else
intYIncrement = 160
intXIncrement = 160
End If
' Medium Tables.
ElseIf optMedRd.Checked = True Then
paramHeight = 96
paramWidth = 96
tblName = "mediumRound.png"
If varArray(UBound(varArray)) = "regularRound.png" Then
For x = 0 To 1
intYIncrement = 216
intXIncrement = 216
Next
intYIncrement = 144
intXIncrement = 144
ElseIf varArray(UBound(varArray)) = "mediumRound.png" Then
intYIncrement = 48
ElseIf varArray(UBound(varArray)) = "smallRound.png" Then
intYIncrement = 48
End If
ElseIf optSmallRd.Checked = True Then
paramHeight = 60
paramWidth = 60
tblName = "smallRound.png"
End If
If ArrayWatch = 0 Then
ReDim Preserve varArray(tblCt - 1)
Else
ReDim Preserve varArray(varArray.Length + (tblCt - 1))
End If
ArrayWatch = ArrayWatch + 1
' Loop and add one table a team based on how many tables the user inputted
For x = 1 To tblCt
Call AddNewTable(paramHeight, paramWidth, tblName)
varArray(NumClicks) = tblName
NumClicks = NumClicks + 1
If (CInt(intX + intXIncrement)) < 950 Then
intX = intX + intXIncrement
ElseIf (CInt(intX + 160)) >= 950 Then
intY = intY + intYIncrement
intX = 48
End If
Next x
End Sub
Public Sub AddNewTable(imgHeight As Integer, imgWidth As Integer, picName As String)
On Error Resume Next
Dim newTable As PictureBox = New PictureBox()
newTable.Image = System.Drawing.Image.FromFile("C:\Documents and Settings\files\" & picName)
newTable.Size = New System.Drawing.Size(imgWidth, imgHeight)
newTable.SizeMode = PictureBoxSizeMode.Normal
newTable.Location = New System.Drawing.Point(intX, intY)
newTable.Visible = True
Me.Controls.Add(newTable)
End Sub
结束班