想在vb.net中使用FOR循环 [英] want to use FOR loop in vb.net
问题描述
我想在FOR循环中添加以下代码..
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)
我想在FOR循环中添加上面的代码...这样我就不必再添加标签和文本框了。我正在制作一个WIN FORM,我必须根据文本数据显示标签和文本框。例如。如果一个txt包含5个URL,那么它应该显示5个TEXT BOXES和5个LABELS ..标签应该自动更改它的号码lyk URL 1,URL 2
如何添加上面的代码进入FOR循环?
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?
推荐答案
试试这个:
Try this:
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)
你真的需要拾取VB.NET上的初学者角色并通过它完成。这是VB.NET 101类型的东西。
You REALLY need to pickup a beginners nook on VB.NET and work through it. This is VB.NET 101 type stuff.
你可以通过谷歌 [< a href =https://www.google.com/search?q=WinForm+VB%3ANET+add+controls+dynamically&ie=utf-8&oe=utf-8&aq=t&rls=org。 mozilla:nb-NO:官方& client = firefox -atarget =_ blanktitle =新窗口> ^ ]搜索。
这看起来很有趣:
http://stackoverflow.com / questions / 10201324 / dynamic-controls-not-rendering-in-winform [ ^ ]
You could esily find that with a Google[^] search.
This looks quite interesting:
http://stackoverflow.com/questions/10201324/dynamic-controls-not-rendering-in-winform[^]
这篇关于想在vb.net中使用FOR循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!