We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add controls to my form in a loop (in VB.NET)

Thread ID:

Created:

Updated:

Platform:

Replies:

638 Jul 18,2002 12:59 PM UTC Jul 18,2002 02:46 PM UTC Windows Forms 1
loading
Tags: FAQ
SoTTo
Asked On July 18, 2002 12:59 PM UTC

How...can i add controls to my form in a loop? i'm trying to figure out how i can do something similar to this vb6 code in vb.NET For i = 1 To 3 Load cmdPrev(i) cmdPrev(i).Visible = False cmdPrev(i).Left = cmdPrev(0).Left + (i * Maat) cmdPrev(i).Top = cmdPrev(0).Top Next i this is just an example.... i could need this to do with some more controls...More than 3... i know i can do this.... (from vb.net help) ' Visual Basic .NET Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click Dim textBox1 As New System.Windows.Forms.TextBox textBox1.Text = "Hello" Me.Controls.Add(textBox1) If Me.Controls.Count > 1 Then MsgBox(Me.Controls(Me.Controls.IndexOf(textBox1)).Text) End If Me.Controls.Remove(button1) End Sub But...that's not exactly what i need.... i need to add the controls in a loop.... plz help :-)

SoTTo
Replied On July 18, 2002 02:46 PM UTC

Private Sub addtextboxes() Dim x, i As Integer, startpos As Integer x = 3 Dim txtCountryCur(x) As TextBox startpos = Me.txtInput.Top + (Me.txtInput.Height * 1.5) For i = 0 To x txtCountryCur(x) = New TextBox() txtCountryCur(x).Text = "test " & i txtCountryCur(x).Left = 0 txtCountryCur(x).Top = txtCountryCur(x).Height * i + startpos Me.Controls.Add(txtCountryCur(x)) Next end sub

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;