how to add some textbox with Code - vb.net

i have trouble with this
Click Here for picture
The Code
Dim Tex1 As TextBox = Nothing
Dim Tex2 As TextBox = Nothing
Tex1 = New Windows.Forms.TextBox
Tex1.Name = "TextBox"
Tex1.Location = New System.Drawing.Point(12, 119)
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
Tex2 = New Windows.Forms.TextBox
Tex2.Name = "TextBox"
Tex2.Location = New System.Drawing.Point(110, 119)
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
i want to add the new textbox with clicking the picture box, like this
Click Here for Picture
but when i click the "add Picture Box" the textbox not appear
please, anyone help me ?

If you want to have the ability to add textboxes to your form then this is what you should do. First you will need to identify the button that you are going to use for this insertion event. I would assume the green plus symbol.
Then I would create a mouse event action like this:
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
' Some action...
End Sub
From there you will be able to insert your code into the click event like this:
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
Dim Tex1 As TextBox = Nothing
Dim Tex2 As TextBox = Nothing
Tex1 = New Windows.Forms.TextBox
Tex1.Name = "TextBox"
Tex1.Location = New System.Drawing.Point(12, 119)
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
Tex2 = New Windows.Forms.TextBox
Tex2.Name = "TextBox"
Tex2.Location = New System.Drawing.Point(110, 119)
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
End Sub
Now there is still a big issue with this code, the location of the textboxes. The reason this is an issue is because they are static, meaning they will always appear in the same spot so, one solution is to declare a global Point() to maintain the location of the newest textbox like this:
Dim tbLocation1 As Point = New Point(12, 199)
Dim tbLocation2 As Point = New Point(110, 199)
From there all you would then need to do is have some sort of margin amount that you want to move the textboxes by like this:
Dim marginAmt As Int32 = 30
Now that all of the pieces are present lets put it together:
Dim tbLocation1 As Point = New Point(12, 199)
Dim tbLocation2 As Point = New Point(110, 199)
Dim marginAmt As Int32 = 30
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
Dim Tex1 As TextBox = New Windows.Forms.TextBox
Dim Tex2 As TextBox = New Windows.Forms.TextBox
' Modifies Tex1
Tex1.Name = "TextBox"
Tex1.Location = tbLocation1
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
' Modifies Tex2
Tex2.Name = "TextBox"
Tex2.Location = tbLocation2
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
' Updates form
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
' Updates the point locations
tbLocation1 = New Point(tbLocation1.X, tbLocation1.Y + marginAmt)
tbLocation2 = New Point(tbLocation2.X, tbLocation2.Y + marginAmt)
End Sub
Now you just need to connect this event action to the button that you desire.

Related

moving many controls together to represent a Seating Chart in VB.NET

Greetings,
I want To create a graphic representation of a seating chart (could be in a wedding venue or in cars...). I used a splitted panel, in the splittedPanel1 i put the buttons to create the cars, and inside the splitted panel2 i want to put the graphic representation. Inside SplittedPanel2, I've created a panel and a pictureBox (to represent some fixed areas in the real world).
I've also created a class called SimpleCar. SimpleCar is composed of 5 TextBox (es) and a PictureBox all in a panel to represent a car: the textBoses represent the passengers names and the car label, and the pictureBox to put an image representing a car (or a table). I've also made a sub to Add dynamically a SimpleCar.
2 problems occur when i want to move this new panel (dynamically created), using MouseDown and MouseUp events:
- first pb: while moving the existing panel, the screen flashes and the movement is not smooth
- second pb: i can't move a panel dynamically created
Note that moving a PictureBox by this code is very smooth but moving a panel is not user friendly.
I expect moving a dynamically created a panel smoothly, or should I reconsider displaying the cars in another way than in a panel?
Knowing that the final purpose of the code is to export a picture of all the created tables in the venue. I also tested the code with a groupBox and the results aren't good.
The simpleCar class is described in the code below:
Class SimpleCar
Public carNameBox, passengerNameBox1, passengerNameBox2,
passengerNameBox3, passengerNameBox4 As TextBox
Public carPictureBox As PictureBox
Public carGroup As Panel
Public Sub New()
carGroup = New Panel
carNameBox = New TextBox With {.Text = "carNmBx",
.BackColor = Color.Yellow,
.Name = "carNmBx"}
passengerNameBox1 = New TextBox With {.Text = "txtPassNmBx1",
.BackColor = Color.BlanchedAlmond,
.Name = "TextBox1"}
passengerNameBox2 = New TextBox With {.Text = "txtPassNmBx2",
.BackColor = Color.AliceBlue,
.Name = "TextBox2"}
passengerNameBox3 = New TextBox With {.Text = "txtPassNmBx3",
.BackColor = Color.Azure,
.Name = "TextBox3"}
passengerNameBox4 = New TextBox With {.Text = "txtPassNmBx4",
.BackColor = Color.Cyan,
.Name = "TextBox4"}
carPictureBox = New PictureBox With {.Text = "picBx1",
.BackColor = Color.BlanchedAlmond,
.Name = "picBox1"}
Dim fdialog As New OpenFileDialog()
fdialog.FileName = String.Empty
fdialog.Multiselect = True
If fdialog.ShowDialog = DialogResult.OK Then
If fdialog.FileNames.Length = 2 Then
carPictureBox.Image = Image.FromFile(fdialog.FileNames(0))
ElseIf fdialog.FileNames.Length = 1 Then
carPictureBox.Image = Image.FromFile(fdialog.FileName)
End If
End If
carGroup.Controls.Add(carPictureBox)
carGroup.Controls.Add(carNameBox)
carGroup.Controls.Add(passengerNameBox1)
carGroup.Controls.Add(passengerNameBox2)
carGroup.Controls.Add(passengerNameBox3)
carGroup.Controls.Add(passengerNameBox4)
End Sub
End Class
To Add dynamically a SimpleCar in the code below:
Public Sub Add_car()
Dim carType As SimpleCar
carType = New SimpleCar
Dim carPs1 = carType.passengerNameBox1
Dim carPs2 = carType.passengerNameBox2
Dim carPs3 = carType.passengerNameBox3
Dim carPs4 = carType.passengerNameBox4
Dim carNm = carType.carNameBox
Dim carPic = carType.carPictureBox
Dim carGroupBox = carType.carGroup
SplitContainer1.Panel2.Controls.Add(carGroupBox)
End Sub
So the problem occurs when i use this code to move a panel (if you replace PictureBox by Panel, even GroupBox) (it worked fine when I wanted to move one control: PictureBox1 in this sample):
'Drag To move PictureBox1 along with mouse-------------------------------------------
Dim oldX As Short
Dim oldY As Short
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
Dim X As Single = e.X
Dim Y As Single = e.Y
PictureBox1.Cursor = Cursors.SizeAll
oldX = CShort(X)
oldY = CShort(Y)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
Dim X As Single = e.X
Dim Y As Single = e.Y
PictureBox1.Cursor = Cursors.Default
End Sub
' to limit the movement within the app----------------------------------
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
Dim ProposedLocation As New Point(PictureBox1.Left - (oldX - e.X), PictureBox1.Top - (oldY - e.Y))
PictureBox1.Left = CInt(IIf(ProposedLocation.X < 0, 0, IIf(ProposedLocation.X > SplitContainer1.Panel2.Width - PictureBox1.Width, SplitContainer1.Panel2.Width - PictureBox1.Width, ProposedLocation.X)))
PictureBox1.Top = CInt(IIf(ProposedLocation.Y < 0, 0, IIf(ProposedLocation.Y > SplitContainer1.Panel2.Height - PictureBox1.Height, SplitContainer1.Panel2.Height - PictureBox1.Height, ProposedLocation.Y)))
End If
End Sub

Generating rows of panels with for loop in VB.NET

I would like to create rows of panels with textboxes using a for loop.
The panels will be created inside another panel (MajorPanel).
The for loop's current value is used to assign values to the textboxes.
The number of rows will be determined by a form (form2) that has a textbox (RowNum) to input number of rows needed in the main form (form1) and use that information for the for loop's counter as shown:
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Ok.Click
Dim Rows As Integer
Rows = RowNum.Text 'RowNum is where to input number of rows needed in form1
Dim TxtBoxPanel As New Panel
Dim LeftBox As New TextBox
Dim CenterBox As New TextBox
Dim RightBox As New TextBox
Dim YAxis As Integer ' for adding TxtBoxPanel in new row
For index = 1 To Rows
'adding the textbox panel
Form1.MajorPanel.Controls.Add(TxtBoxPanel) 'referring to form1 as panel needed in form1
TxtBoxPanel.Name = ("txtBoxPanel" & index)
TxtBoxPanel.Size = New Size(610, 32)
YAxis = +32
TxtBoxPanel.Location = New Point(3, YAxis)
'adding left box
TxtBoxPanel.Controls.Add(LeftBox)
LeftBox.Name = ("LeftBox" & index)
LeftBox.Text = (index)
LeftBox.Size = New Size(100, 20)
LeftBox.Location = New Point(3, 3)
'adding center box
TxtBoxPanel.Controls.Add(CenterBox)
CenterBox.Name = ("CenterBox" & index)
CenterBox.Text = (index)
CenterBox.Size = New Size(100, 20)
CenterBox.Location = New Point(258, 3)
'adding right box
TxtBoxPanel.Controls.Add(RightBox)
RightBox.Name = ("RightBox" & index)
RightBox.Size = New Size(100, 20)
RightBox.Text = (index)
RightBox.Location = New Point(495, 3)
Next index
Close()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles RowNum.TextChanged
End Sub
End Class
However, when I execute, the panels generate one on top of the other as shown:
After execution for 23 rows
This is the desired result I would like:
Rows of panels within MajorPanel
form1 has only one line of code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Show()
End Sub
End Class
In a quick glance, it looks like you are using YAxis = +32 when you should be using YAxis += 32.
The first one is just setting YAxis to the value 32, and the second one is incrementing it by 32, which is what you want (I assume)
There are two issues:
1- You are adding same instance of TxtBoxPanel to MajorPanel which means it will overwrite the previous location and you will end up only having single TxtBoxPanel at the bottom of MajorPanel because you are not creating new instead updating coordinates of same instance which got created before starting loop.
2- "YAxis = +32" should be "YAxis +=32
Here is updated code.. it should give you desired result.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Ok.Click
Dim Rows As Integer
Rows = RowNum.Text 'RowNum is where to input number of rows needed in form1
Dim YAxis As Integer ' for adding TxtBoxPanel in new row
For index = 1 To Rows
Dim TxtBoxPanel As New Panel
Dim LeftBox As New TextBox
Dim CenterBox As New TextBox
Dim RightBox As New TextBox
'adding the textbox panel
Form2.MajorPanel.Controls.Add(TxtBoxPanel) 'referring to form1 as panel needed in form1
TxtBoxPanel.Name = ("txtBoxPanel" & index)
TxtBoxPanel.Size = New Size(610, 32)
YAxis +=32
TxtBoxPanel.Location = New Point(3, YAxis)
'adding left box
TxtBoxPanel.Controls.Add(LeftBox)
LeftBox.Name = ("LeftBox" & index)
LeftBox.Text = (index)
LeftBox.Size = New Size(100, 20)
LeftBox.Location = New Point(3, 3)
'adding center box
TxtBoxPanel.Controls.Add(CenterBox)
CenterBox.Name = ("CenterBox" & index)
CenterBox.Text = (index)
CenterBox.Size = New Size(100, 20)
CenterBox.Location = New Point(258, 3)
'adding right box
TxtBoxPanel.Controls.Add(RightBox)
RightBox.Name = ("RightBox" & index)
RightBox.Size = New Size(100, 20)
RightBox.Text = (index)
RightBox.Location = New Point(495, 3)
Next index
Close()
End Sub

How to declare textbox as a global variable?

I have declared a textbox via button click:
Dim tp = TabControl2.TabPages(TabControl2.TabPages.Count - 1)
Dim txtbox As New TextBox()
txtbox.Location = New Point(200, 0)
txtbox.Height = 20
txtbox.Width = 100
tp.Controls.Add(txtbox)
Now I want a label in another sub to display the content of the textbox. My first attempt was:
label.Text = txtbox.text
But that didn't work because my textbox was declared locally and I have no idea how to declare this as a global variable...
You should try to avoid global variables if there are workarounds for the task you have. For example you can retrieve your textbox from the Controls collection where you have added it. You just need something to help you locate the right textbox.
Dim tp = TabControl2.TabPages(TabControl2.TabPages.Count - 1)
Dim txtbox As New TextBox()
txtbox.Location = New Point(200, 0)
txtbox.Height = 20
txtbox.Width = 100
txtbox.Name = "MyImportantTextBox"
tp.Controls.Add(txtbox)
Now when you want to retrieve it
Dim tp = TabControl2.TabPages(TabControl2.TabPages.Count - 1)
Dim textbox = tp.Controls.
OfType(Of TextBox).
FirstOrDefault(Function(x) x.Name = "MyImportantTextBox")
if textbox IsNot Nothing Then
label.Text = textbox.Text
End If
There is also another simpler possibility, add an handler for the textbox TextChanged event and when you type something in that textbox reflect the content in the label.
Dim tp = TabControl2.TabPages(TabControl2.TabPages.Count - 1)
Dim txtbox As New TextBox()
txtbox.Location = New Point(200, 0)
txtbox.Height = 20
txtbox.Width = 100
AddHandler txtbox.TextChanged, AddressOf OnMyTextBoxChange
tp.Controls.Add(txtbox)
And add an event handler for the txtbox like this
Sub OnMyTextBoxChange(sender as Object, e as EventArgs)
Dim txtbox = DirectCast(sender, TextBox)
label.Text = txtbox.Text
End Sub
The issue is you never set the text property. Try this:
Dim tp = TabControl2.TabPages(TabControl2.TabPages.Count - 1)
Dim txtbox As New TextBox()
txtbox.Text = "Some Text"
txtbox.Location = New Point(200, 0)
txtbox.Height = 20
txtbox.Width = 100
tp.Controls.Add(txtbox)
I added one line of code to your example.
Bryan had a good idea.
My personal choice would be declaring a global string variable and during your button click procedure assigning it the value of your textbox.

Remove LineShape from Windows Form, LineShape and ShapeContainer Arrays

I am using the code below to add multiple LineShape controls to a Windows Form. Note the globally declared mLineShapes() and mShapeContainter() arrays (at bottom of code) which store each new LineShape object once it's created.
At present, I have been unsuccessful at removing a given LineShape control from the form (even if I know its array index), and also cannot removing an array element without causing a Nothing for the removed element. Obviously, once I remove the element from these arrays, it requires that all the remaining elements with greater indices are copied to lower values to fill in the Nothing voided element. Given these circumstances, can lists be used instead of the mLineShapes() and mShapeContainer() arrays?
enter code here' create new ShapeContainer
Dim sSCTemp As New ShapeContainer
' add ShapeContainer to Form
sSCTemp.Parent = Me
' create new LineShape
Dim sLSTemp As New LineShape
sLSTemp.BorderColor = Color.Black
sLSTemp.BorderWidth = 2
sLSTemp.Cursor = Cursors.Cross
' add LineShape to ShapeContainer
sLSTemp.Parent = sSCTemp
' set starting and ending coordinates for the line
sLSTemp.StartPoint = New System.Drawing.Point(siSCCount * 20, 60 + siSCCount * 60)
sLSTemp.EndPoint = New System.Drawing.Point(100 + siSCCount * 20, 110 + siSCCount * 60)
' set new LineShape to top of z-order
sLSTemp.BringToFront()
sSCTemp.BringToFront()
' connect ContextMenuStrip to LineShape
sLSTemp.ContextMenuStrip = mLsCtm1
' add new LineShape to arrays
ReDim Preserve mLineShapes(siSCCount)
ReDim Preserve mShapeContainer(siSCCount)
mLineShapes(siSCCount) = sLSTemp
mLineShapes(siSCCount).Name = "LineShape" & siSCCount
mShapeContainer(siSCCount) = sSCTemp
mShapeContainer(siSCCount).Name = "ShapeContainer" & siSCCount
In addition to the above, the endpoints of each
LineShape are selected from the arrays so that they can be moved. An example is below:
Dim siSCId As Integer
Dim myShapeContainer As ShapeContainer
myShapeContainer = CType(sender, ShapeContainer)
Dim myLineShape As LineShape
' get index of the actual ShapeContainer in ShapeContainer array
siSCId = Array.IndexOf(mShapeContainer, sender)
If siSCId > -1 Then
myLineShape = mLineShapes(siSCId)
If MouseIsNearBy(myLineShape.EndPoint) Then
myLineShape.BorderColor = Color.Red
NearLineEndPoint = True
End If
If MouseIsNearBy(myLineShape.EndPoint) = False Then
myLineShape.BorderColor = Color.Black
NearLineEndPoint = False
End If
If (dragStartPoint) Then
myLineShape.StartPoint = New Point(oldStartPoint.X + e.X - oldMouseX, oldStartPoint.Y + e.Y - oldMouseY)
End If
End If
Therefore, If I simply add a new LineShape to the form controls without using the mLineShapes() ans mShapeControl() arrays, how can I modify the above code (which finds the LineShape in the storage arrays) so that the line can be modified? I think that if I click on a LineShape, I can get its name using .sourcecontrol or .parent?
UPDATE 5/9/2019
After right clicking on a control on Form1 and selecting the "Link" command from a ContextMenuStrip, the following method (ctmsconnect) is fired to draw a new LineShape control that the user then drags and drops on to the next control in the workflow. Question is, is the list of LineShapes ("Lines") not needed?
(in Form1 class declarations):
Dim SC As New ShapeContainer
Dim Lines As New List(Of LineShape)
Private Sub ctmsconnect_Click(sender As System.Object, e As System.EventArgs) Handles ctmsconnect.Click
mLineWidth = 1
Dim myItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
Dim cms As ContextMenuStrip = CType(myItem.Owner, ContextMenuStrip)
Dim x As Integer = cms.SourceControl.Right - 2
Dim y As Integer = cms.SourceControl.Top + (cms.SourceControl.Height / 2 - 12)
Dim LS As New LineShape
NumLineShapes += 1
LS.Name = "LineShape" & NumLineShapes
LS.BorderColor = Color.Black
LS.BorderWidth = 2
'Set starting and ending coordinates for the line
LS.StartPoint = New Point(x, y)
LS.EndPoint = New Point(x + 80, y - 5)
'Set new LineShape to top of z-order
LS.BringToFront()
Dim nxgContextMenuStrip As New ContextMenuStrip
LS.ContextMenuStrip = nxgContextMenuStrip
LS.Tag = "LineShape" & NumLineShapes & "_Delete"
'Attach an event handler for the ContextMenuStrip control's Opening event.
AddHandler nxgContextMenuStrip.Opening, AddressOf cms_Opening
numconnectedlineendpoints += 1
Dim myValues As New List(Of String)
myValues.Add(cms.SourceControl.Name)
DropLineOriginalObjectName = cms.SourceControl.Name
OrigDropControl = cms.SourceControl
myValues.Add(LS.Name)
myValues.Add("linestart")
dicGUIControls.Add(numconnectedlineendpoints, myValues)
Lines.Add(LS)
SC.Shapes.Add(LS)
Me.Refresh()
End Sub
You shouldn't need the arrays, just use the controls collection. Instead of setting the parent of the controls, you should probably add them to the collection:
'sSCTemp.Parent = Me
Me.Controls.Add(sSCTemp)
To remove them, you can reference them by the name property:
If Me.Controls.ContainsKey("ShapeContainer1") Then
Me.Controls.RemoveByKey("ShapeContainer1")
End If
The shape controls inside the ShapeContainer have to be accessed through the Shape collection:
If Me.Controls.ContainsKey("ShapeContainer1") Then
Dim sc As ShapeContainer = DirectCast(Me.Controls("ShapeContainer1"), ShapeContainer)
If sc.Shapes.ContainsKey("LineShape2") Then
sc.Shapes.RemoveAt(sc.Shapes.IndexOfKey("LineShape2"))
End If
End If
Example of reading the StartPoint and EndPoint properties:
Dim sb As New StringBuilder
For Each ls As LineShape In Me.ShapeContainer1.Shapes
sb.AppendLine(ls.StartPoint.ToString & " - " & ls.EndPoint.ToString)
Next
MessageBox.Show(sb.ToString)
Note: ShapeContainer Class makes a special note:
Be careful that you do not create more than one ShapeContainer for each form or container; doing this may introduce unexpected behavior. If you add a design-time line or shape control to a form or container after you write code to create one programmatically, you should modify that code to use the ShapeContainer created by the designer.
Public Class Form1
Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
' Set the form as the parent of the ShapeContainer.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
canvas.Parent = Me
' Set the ShapeContainer as the parent of the LineShape.
End Sub
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
If RadioButton1.Checked = True Then
Dim line1 As New Microsoft.VisualBasic.PowerPacks.LineShape
line1.Parent = canvas
' Set the starting and ending coordinates for the line.
line1.StartPoint = New System.Drawing.Point(Me.Width / 2, 0)
line1.EndPoint = New System.Drawing.Point(e.X, e.Y)
TextBox1.Text = canvas.Shapes.Count.ToString
line1.Name = "MyShape"
canvas.Shapes.Add(line1)
AddHandler line1.Click, AddressOf LineClick
End If
End Sub
Private Sub LineClick(sender As Object, e As EventArgs)
' Here is where we take the object that is sender from the arguments and cast it to its specific control
If RadioButton2.Checked = True Then
' I could just as easily use
CType(sender, PowerPacks.LineShape).Dispose()
TextBox1.Text = canvas.Shapes.Count
End If
End Sub
End Class

Cant create 2nd textbox

I'm having problems with this code and I can't figure out why. It works fine the first time through but crashes with a "Parameter is not Valid" error the 2nd time through on this line:
Dim tbx As TextBox = New Windows.Forms.TextBox
The full code is as follows:
Dim tbx As TextBox = New Windows.Forms.TextBox
tbx.Name = tbxName
tbx.Size = New System.Drawing.Size(55, 12)
tbx.BorderStyle = BorderStyle.None
tbx.TextAlign = HorizontalAlignment.Center
Using f As Font = tbx.Font
tbx.Font = New Font(f.FontFamily, 8, FontStyle.Bold)
End Using
tbx.Location = New System.Drawing.Point(xCords, 44)
Select Case tbx.Name
Case "tbxBulk01" : tbx.Text = Bulk01Label
Case "tbxBulk02" : tbx.Text = Bulk02Label
End Select
Me.Controls.Add(tbx)
Here's the stack trace:
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.get_FontHeight()
at System.Windows.Forms.TextBoxBase.get_PreferredHeight()
at System.Windows.Forms.TextBoxBase.get_DefaultSize()
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.TextBoxBase..ctor()
at System.Windows.Forms.TextBox..ctor()
Any help is appreciated.
I know this is an old question but here is my answer.
I suspected the
USING .... END USING section as well.
I have just read that in the feedback too, oh well, never mind.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xCoords As Integer = 80
Dim myTextBox As TextBox = New TextBox
For index As Integer = 1 To 2
myTextBox = New TextBox
myTextBox.Name = "MyTextBox" & index.ToString
myTextBox.Size = New System.Drawing.Size(55, 12)
myTextBox.BorderStyle = BorderStyle.None
myTextBox.TextAlign = HorizontalAlignment.Center
myTextBox.Font = New System.Drawing.Font(myTextBox.Font.FontFamily, 8, FontStyle.Bold)
myTextBox.Location = New System.Drawing.Point(index * xCoords, 44)
Select Case index
Case 1 : myTextBox.Text = "Bulk01Label"
Case 2 : myTextBox.Text = "Bulk02Label"
End Select
Me.Controls.Add(myTextBox)
Next
End Sub
End Class