Click here to Skip to main content
15,917,608 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to add the following code in FOR loop..
Dim label As New Label()
label.Location = New Point(13, 13)
label.Text = Name
Me.Controls.Add(label)
'Textbox
Dim textbox As New TextBox()
textbox.Location = New Point(60, 60)
textbox.Text = "URL"
Me.Controls.Add(Textbox)


I want to add the above code in FOR loop...so that I don't have to add label and textbox again. I am making a WIN FORM in which I have to display label and textbox according to the text data. For eg. if a txt contains 5 URL so it should display 5 TEXT BOXES and 5 LABELS..and label should automatically change its number lyk URL 1, URL 2

How to add the above code into FOR loop?
Posted
Updated 30-Apr-13 9:06am
v2
Comments
Richard C Bishop 30-Apr-13 15:07pm    
Write the syntax for a "FOR" loop and cut and paste that code between the starting and ending points of the loop.
shashank 1068 30-Apr-13 15:13pm    
hw???
i don't know abt vb.net can u plz tell me?
Richard C Bishop 30-Apr-13 15:24pm    
So how did you write the code you posted? Did you have to look it up somewhere or did you just already know it? Use google next time, it is your friend.
[no name] 30-Apr-13 15:30pm    
Just like you have already been told, at least once. Get yourself some books on VB.NET, find some tutorials, take a class at your local college or university.

Try this:
VB
For i As Integer = 0 To 4
	Dim label As New Label()
	label.Location = New Point(13, 13 + (i * 30))
	label.Text = Name
	Me.Controls.Add(label)
	'Textbox
	Dim textbox As New TextBox()
	textbox.Location = New Point(60, 13 + (i * 30))
	textbox.Text = "URL"
	Me.Controls.Add(textbox)
Next
(I altered the control locations so they would look vaguely ok)
 
Share this answer
 
Comments
Maciej Los 30-Apr-13 16:24pm    
My 5!
shashank 1068 1-May-13 0:14am    
thnx :)
OriginalGriff 1-May-13 3:38am    
You're welcome!
You REALLY need to pickup a beginners nook on VB.NET and work through it. This is VB.NET 101 type stuff.
 
Share this answer
 
You could esily find that with a Google[^] search.

This looks quite interesting:
http://stackoverflow.com/questions/10201324/dynamic-controls-not-rendering-in-winform[^]
 
Share this answer
 
Comments
Maciej Los 30-Apr-13 16:25pm    
Good, general suggestion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900