Note that there are some explanatory texts on larger screens.

plurals
  1. POVB dynamically add picture boxes of different sizes with equal spacing
    primarykey
    data
    text
    <p>So basically I have a program that lets users pick from regular round tables, medium rounds, and small rounds and they also type in the amount they want. I need the form to work so that all tables (no matter the size) are added to the form dynamically but with equal spacing of 48px (2 feet). The code below is what I've been working on, but it's getting messy and I don't think it will ever account for all circumstances.</p> <pre><code>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)) &lt; 950 Then intX = intX + intXIncrement ElseIf (CInt(intX + 160)) &gt;= 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\" &amp; 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 </code></pre> <p>End Class</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload