0

vb2005で実行時に複数のテキスト ボックスを作成する方法は?

コーディングを教えてください。

 dim st as string
    dim rownum as integer=36
    For j As Integer = 0 To dt.Rows.Count - 1
                   rownum= rownum +  rownum 
                    st = "txt"
                     Dim "txt" & CStr(j) As New TextBox
                    "txt" & CStr(j).location(0,rownum)
    Next
4

2 に答える 2

0

次のようなことを試してください:

For j As Integer = 0 To dt.Rows.Count - 1
    Dim tb As New TextBox()
    rownum += rownum

    Me.Controls.Add(tb)
    tb.Location = New Point(0, rownum)
    tb.Name = "txt" & j.ToString()        
Next

次に、その名前でアクセスできます。

Me.Controls("txt5").Text = "blah bleh"
于 2013-08-30T05:18:10.867 に答える
0

以下のコードを使用して、実行時に複数のテキストボックスを作成できます。

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim newbox As TextBox
    For i As Integer = 1 To 5 ' 5 indecates the number of textbox you want to create.
        'create a new textbox and set its properties
        newbox = New TextBox
        newbox.Size = New Drawing.Size(100, 20)
        newbox.Location = New Point(10, 10 + 25 * (i - 1))
        newbox.Name = "TextBox" & i
        newbox.Text = newbox.Name
        'connect it to a handler, save a reference to the array and add it to the form controls
        AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged
        boxes(i) = newbox
        Me.Controls.Add(newbox)
    Next
End Sub


Private Sub TextBox_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'when you modify the contents of any textbox, the name of that textbox and
    'its current contents will be displayed in the title bar
    Dim box As TextBox = DirectCast(sender, TextBox)
    Me.Text = box.Name & ": " & box.Text
End Sub

それがうまくいくかどうか教えてください。

よろしく。

于 2013-08-30T05:22:39.817 に答える