从动态创建文本框和复选框中获得价值框中、文本框、复选、价值

由网友(晚风)分享简介:我写了下面的code创建code i write the following code to create codeDim i, x, y As Integerx = 30y = 25i = 0For i = 0 To dt1.Rows.Count - 1Dim chk As New CheckBox()chk.T...

我写了下面的code创建code

i write the following code to create code

Dim i, x, y As Integer
    x = 30
    y = 25
    i = 0
    For i = 0 To dt1.Rows.Count - 1
        Dim chk As New CheckBox()
        chk.Text = dt1.Rows(i)(0)
        chk.Location = New Point(x, y)
        chk.Font = fnt
        chk.Width = 450
        chk.ForeColor = Color.White

        Me.Panel1.Controls.Add(chk)
        chk.Name = "chk" & Convert.ToString(i)
        Dim txt As New TextBox
        txt.Location = New Point(x, y + 23)
        txt.Font = fnt
        txt.Multiline = True
        txt.Height = 46
        txt.Width = 400
        Me.Panel1.Controls.Add(txt)
        txt.Name = "txt" & Convert.ToString(i)
        y = y + 69

我想以检索复选框的选中属性为true和各自的文本框在ButtonClick事件的textvalue。问题是找到了控制及其textvalue。 任何一个可以帮助?谢谢Advance.dt1的数据表。对于窗口窗体应用程序

i want to retrive the textvalue of checkbox whose checked property is true and respective textbox at a buttonclick event. Problem is in finding the controls and their textvalue. any one can help?Thanks in Advance.dt1 is datatable .For window form application

推荐答案

创建一个新的VB Windows窗体应用程序,然后添加一个按钮替换此code形式的code:

Create a new VB Windows Form application and add a button then replace the code of the form with this code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim txt As New TextBox
        txt.Name = "myText"
        txt.Left = Me.Width / 2
        txt.Top = Me.Height / 2
        txt.Text = "here is my text"

        Me.Controls.Add(txt)              'This will add the dynamically created object

        Dim anotherObj As TextBox = Me.Controls.Item("myText")    'because we know the name of the object we created before, we can retreive it back

        MsgBox(anotherObj.Text)      'and we can also get the text we assigned earlier.


    End Sub


End Class

最后两行可以在另一个小组(放),你仍然有同样的结果。

The last 2 lines can be put inside another Sub() and you would still have the same result.

阅读全文

相关推荐

最新文章