vb.net将label.text复制到相应的文本框

时间:2017-01-22 05:22:11

标签: vb.net hyperlink textbox label

我有一个包含大量文本框及其标签的表单 我想通过代码

将label.text复制到其对应的文本框标签

如何为每个文本框选择左侧标签

1 个答案:

答案 0 :(得分:0)

这是我的解决方案 我在这里张贴,所以有人可以帮助他解决类似问题 我创建了文本框来保存表中的数据和相应标签,每个文本框都具有默认大小

Shared Function addTextboxCheckBoxFromTable(ByVal container As Control, tablename As String) As Integer
    'With grid
    Dim count As Integer = cValidation.ColumnCount(tablename)
    Dim DefaultXLabel As Integer
    DefaultXLabel = 45
    ' Dim count As Integer = (.Columns.Count - 1)
    Dim xlabel, ylabel, xText, ytext, count2 As Integer
    ''''//start from where
    xlabel = DefaultXLabel
    xText = 1
    ylabel = 1
    ytext = 25  ' space between label and text
    Dim gstrSQL As String
    For i As Integer = 1 To count
        gstrSQL = "select ORDINAL_POSITION,COLUMN_NAME from information_schema.columns "
        gstrSQL &= String.Format("where TABLE_NAME =  '{0}' ", tablename)
        gstrSQL &= "and ORDINAL_POSITION= " & i

        Dim CheckBox1 As New System.Windows.Forms.CheckBox
        ' Dim Combo1 As New ComboBox
        Dim NameCol, TagCol As String

        NameCol = CSql.SearchQry(gstrSQL, "COLUMN_NAME")
        TagCol = NameCol
        '      MsgBox(.Columns(i).Tag)
        If String.Compare(TagCol.ToLower, "depname", False) = 0 Then
            Dim combo1 As New ComboBox() With
                            {
                            .Name = String.Format("cmb{0}", TagCol),
                            .Tag = TagCol,
                            .AccessibleDescription = NameCol,
                            .Location = New System.Drawing.Point(xText, ytext),
                            .Width = 200
                            }
            container.Controls.Add(combo1)
            CSql.SqlToCombo("select depname from departments", combo1)

        ElseIf String.Compare(TagCol, "outtype", True) = 0 Then
            Dim combo1 As New ComboBox() With
                            {
                            .Name = String.Format("cmb{0}", TagCol),
                            .Tag = TagCol,
                            .AccessibleDescription = NameCol,
                            .Location = New System.Drawing.Point(xText, ytext),
                            .Width = 200
                            }
            container.Controls.Add(combo1)
            CSql.SqlToCombo("select type from outtype", combo1)
        ElseIf String.Equals(TagCol, "out", StringComparison.CurrentCultureIgnoreCase) Then

            Dim combo1 As New ComboBox() With
                            {
                            .Name = String.Format("cmb{0}", TagCol),
                            .Tag = TagCol,
                            .AccessibleDescription = NameCol,
                            .Location = New System.Drawing.Point(xText, ytext),
                            .Width = 200
                            }

            container.Controls.Add(combo1)
            combo1.Items.Add("true")
            combo1.Items.Add("false")
            'CSql.SqlToCombo("select type from outtype", combo1)

        Else
            Dim _
                        text1 As _
                            New System.Windows.Forms.TextBox() _
                            With {.Tag = TagCol, .Name = String.Format("txt{0}", TagCol),
                            .AccessibleDescription = NameCol, .Location = New System.Drawing.Point(xText, ytext), .Width = 200}
            container.Controls.Add(text1)

        End If
        With CheckBox1

            .Text = NameCol
            .Tag = NameCol
            .Name = String.Format("chk{0}", TagCol)
            .AccessibleDescription = NameCol
            .Location = New System.Drawing.Point(xlabel, ylabel)
            .Width = 200
        End With

        xText = xText + 201
        xlabel = xlabel + 201
        If count2 = 4 Then  ' new line 
            count2 = 0
            ylabel += 45
            ytext += 45
            xlabel = DefaultXLabel
            xText = 1
        Else
            count2 += 1
        End If
        container.Controls.Add(CheckBox1)
    Next
    Dim xText1 As Integer
    ytext = ytext + 30
    For Each oc As Control In container.Controls
        If TypeOf (oc) Is Button Then
            oc.Location = New System.Drawing.Point(xText1, ytext)
            xText1 = xText1 + 150
        End If

    Next
    Return ytext
    'End With
End Function