Como crear un TextBox en tiempo de ejecución
Cita de milvio en 18 de noviembre de 2024, 22:41
Public Class Form2
Dim Contador As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newTB As New TextBox
newTB.Name = "tbNew" & ContadorMe.Controls.Add(newTB)
newTB.Width = 200
newTB.Multiline = True
newTB.Height = 100Panel1.Controls.Add(newTB)
Contador += 1
CambiarPosicion()
End SubPublic Sub CambiarPosicion()
Dim Posicion As Single = 0
For Each Txt As Control In Panel1.Controls
If TypeOf Txt Is TextBox Then
Txt.Top = Posicion
Txt.Width = Panel1.Width
Txt.Height = Txt.Width * 0.6Posicion = Txt.Top + Txt.Height
End If
NextEnd Sub
End Class
Public Class Form2
Dim Contador As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newTB As New TextBox
newTB.Name = "tbNew" & Contador
Me.Controls.Add(newTB)
newTB.Width = 200
newTB.Multiline = True
newTB.Height = 100
Panel1.Controls.Add(newTB)
Contador += 1
CambiarPosicion()
End Sub
Public Sub CambiarPosicion()
Dim Posicion As Single = 0
For Each Txt As Control In Panel1.Controls
If TypeOf Txt Is TextBox Then
Txt.Top = Posicion
Txt.Width = Panel1.Width
Txt.Height = Txt.Width * 0.6
Posicion = Txt.Top + Txt.Height
End If
Next
End Sub
End Class