1

Windows フォーム、VS 2012、VB.NET

私はいくつかのコードを試しましたが、どういうわけかダンテキストボックスがパネル内に配置されていません。

サンプルコード:

 For Each name As String In li
                Dim Answer As String() = AnsStrPerItem(i).Split(",")
                'addField(NameOfPanel,Width,Height,LocationX,LocationY,color White=white else gray)
                'addPanel("Panel" & i.ToString, 1100, 529, 3, (12 + (i * 89)), "White")
                'addField(NameOfButton,TextOfButton,Width,Height,LocationX,LocationY,readonly 0 = true)
                addField("Q" & i.ToString, name.ToString, 533, 64, 14, (69 + (i * 89)), 0)
                addField("A" & i.ToString, Answer(1), 553, 64, 597, (69 + (i * 89)), 1)
                i += 1
            Next

実際にパネル/txtboxを追加するコード

Public Function addPanel(ByVal NameOfPanel As String, ByVal Width As Integer, ByVal Height As Integer, ByVal LocationX As Integer, ByVal LocationY As Integer, ByVal color As String)

    '------------------------ADDING FIELDS INTO FORM TO SIMULATE A DATAREPEATER

    'INSTANTIATE CONTROL
    Dim Panel As System.Windows.Forms.Panel

    'CREATE CONTROL
    Panel = New System.Windows.Forms.Panel()

    'SET TEXT PROPERTIES
    Panel.Name = NameOfPanel
    Panel.Size = New System.Drawing.Size(Width, Height)
    Panel.Location = New System.Drawing.Point(LocationX, LocationY)

    If color = "White" Then Panel.BackColor = Drawing.Color.White Else Panel.BackColor = Drawing.Color.LightGray

    'ADD CONTROL TO FORM1'S COLLECTION
    Form1.Panel5.Controls.Add(Panel)

    Return Nothing

End Function

Public Function addField(ByVal NameOfButton As String, ByVal TextOfButton As String, ByVal Width As Integer, ByVal Height As Integer, ByVal LocationX As Integer, ByVal LocationY As Integer, ByVal ro As Integer)

    '------------------------ADDING FIELDS INTO FORM TO SIMULATE A DATAREPEATER

    'INSTANTIATE CONTROL
    Dim txtb As System.Windows.Forms.TextBox

    'CREATE CONTROL
    txtb = New System.Windows.Forms.TextBox()

    'SET TEXT PROPERTIES
    txtb.Name = NameOfButton
    txtb.Size = New System.Drawing.Size(Width, Height)
    txtb.Location = New System.Drawing.Point(LocationX, LocationY)
    txtb.Text = TextOfButton
    txtb.Multiline = True
    Dim myfont As New Font("Microsoft Sans Serif", 16, FontStyle.Regular)
    txtb.Font = myfont
    If ro = 0 Then txtb.ReadOnly = True

    'ADD CONTROL TO FORM1'S COLLECTION
    Form1.Panel5.Controls.Add(txtb)

    Return Nothing

End Function
4

3 に答える 3

2

少し明確にする必要があるかもしれません。最初の関数では、パネルにパネルを追加しています。2 番目の関数では、親パネルにテキスト ボックスを追加します。子パネルがテキスト ボックスの上にある場合は、おそらく非表示になっています。子パネルにテキストボックスを追加したい場合は、次のように動作するはずです:

Form1.Panel5.Controls(Form1.Panel5.Controls.IndexOfKey(NameOfPanel)).Controls.Add(txtb)
于 2013-05-23T17:03:34.643 に答える
1

コントロールの追加

For Each name As String In li
                'addField(NameOfPanel,Width,Height,LocationX,LocationY,color White=white else gray)
                If ((i Mod 2) = 0) Then
                    addPanel("pQna" & i.ToString, 1138, 100, 3, (i * 89), "Lgray")
                Else
                    addPanel("pQna" & i.ToString, 1138, 100, 3, (i * 89), "White")
                End If
                'addField(NameOfButton,TextOfButton,Width,Height,LocationX,LocationY,readonly 0 = true)
                addField("Q" & i.ToString, name.ToString, 533, 64, 14, 14, 0, i)
                addField("A" & i.ToString, "", 553, 64, 597, 14, 1, i)
                i += 1
            Next
    Return Nothing
End Function

パネルを追加する

Public Function addPanel(ByVal NameOfPanel As String, ByVal Width As Integer, ByVal Height As Integer, ByVal LocationX As Integer, ByVal LocationY As Integer, ByVal color As String)

    '------------------------ADDING FIELDS INTO FORM TO SIMULATE A DATAREPEATER

    'INSTANTIATE CONTROL
    Dim Panel As System.Windows.Forms.Panel

    'CREATE CONTROL
    Panel = New System.Windows.Forms.Panel()

    'SET TEXT PROPERTIES
    Panel.Name = NameOfPanel
    Panel.Size = New System.Drawing.Size(Width, Height)
    Panel.Location = New System.Drawing.Point(LocationX, LocationY)

    If color = "White" Then Panel.BackColor = Drawing.Color.White Else Panel.BackColor = Drawing.Color.LightGray

    'ADD CONTROL TO FORM1'S COLLECTION
    Form1.pQnA.Controls.Add(Panel)

    Return Nothing

End Function

パネル内にテキストボックスを追加する

Public Function addField(ByVal NameOfButton As String, ByVal TextOfButton As String, ByVal Width As Integer, ByVal Height As Integer, ByVal LocationX As Integer, ByVal LocationY As Integer, ByVal ro As Integer, ByVal i As Integer)
    '-----------------------FINDING PANEL

    For Each pnl As Control In Form1.pQnA.Controls
        If TypeOf pnl Is Panel Then
            Dim var As String = pnl.Name.ToString
            If pnl.Name.Equals("pQna" & i.ToString) Then


                '------------------------ADDING FIELDS INTO FORM TO SIMULATE A DATAREPEATER

                'INSTANTIATE CONTROL
                Dim txtb As System.Windows.Forms.TextBox

                'CREATE CONTROL
                txtb = New System.Windows.Forms.TextBox()

                'SET TEXT PROPERTIES
                txtb.Name = NameOfButton
                txtb.Size = New System.Drawing.Size(Width, Height)
                txtb.Location = New System.Drawing.Point(LocationX, LocationY)
                txtb.Text = TextOfButton
                txtb.Multiline = True
                Dim myfont As New Font("Microsoft Sans Serif", 16, FontStyle.Regular)
                txtb.Font = myfont
                If ro = 0 Then txtb.ReadOnly = True

                'ADD CONTROL TO FORM1'S COLLECTION
                'Form1.pQnA.Controls.Add(txtb)
                DirectCast(pnl, Panel).Controls.Add(txtb)

            End If
        End If
    Next

    Return Nothing

End Function
于 2013-05-23T17:28:34.850 に答える