0

Visual Basic (コードを使用) で、別のパネル内で複製する必要がある複数のラベル、TextBox などを含むパネルを作成しました。繰り返しパネルを作成するコーディングは次のようになります。

Public Class frmOrderEntry2

Dim a As Integer = 2
Dim x As Integer = 160

Public Sub frmOrderEntry2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '
    'This loads the module name and system date
    Dim today1 As String = Today.Date()
    txbDate.Text = today1
    txbDate.ForeColor = Color.White
    txbDate.BackColor = Color.DarkBlue
    txbDate.ReadOnly = True
    txbLineNumber.Text = 1

End Sub

Private Sub btnCreateNewLine_(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateNewLine.Click

    Dim b As String = Short.Parse(a)

    'This creates the label "Part No."

    Dim lblPrtNo As New Label()
    lblPrtNo.Name = "lblPrtNo" & Convert.ToString(b)
    lblPrtNo.Text = "Part Number"
    lblPrtNo.ForeColor = Color.White
    lblPrtNo.Font = New Font("Sans Serif", 9)
    lblPrtNo.Font = New Font(lblPrtNo.Font, FontStyle.Regular)
    lblPrtNo.Location = New Point(13, 8)
    lblPrtNo.Size = New Size(77, 15)
    Me.Controls.Add(lblPrtNo)
    '
    'This generates the textbox for the user to enter the Part No.
    Dim txbPartNo As New TextBox()
    txbPartNo.Name = "txbPartNo" & Convert.ToString(b)
    txbPartNo.Text = ""
    txbPartNo.ForeColor = Color.Black
    txbPartNo.BackColor = Color.Yellow
    txbPartNo.Font = New Font("Sans Serif", 10)
    txbPartNo.Font = New Font(txbPartNo.Font, FontStyle.Bold)
    txbPartNo.Location = New Point(16, 26)
    txbPartNo.Size = New Size(263, 22)
    txbPartNo.Cursor = Cursors.Hand
    txbPartNo.AcceptsReturn = True
    txbPartNo.AcceptsTab = True
    txbPartNo.TabIndex = 10
    AddHandler txbPartNo.TextChanged, AddressOf txbPartNo_Textchanged
    Me.Controls.Add(txbPartNo)
    '
    ' This generates the button control to do a part number search
    Dim btnPartNoSearch As New Button()
    btnPartNoSearch.Name = "btnPartNoSearch"
    btnPartNoSearch.Text = "S"
    btnPartNoSearch.FlatStyle = FlatStyle.Popup
    btnPartNoSearch.FlatAppearance.BorderColor = Color.Black
    btnPartNoSearch.FlatAppearance.BorderSize = 2
    btnPartNoSearch.Cursor = Cursors.Hand
    btnPartNoSearch.TabIndex = 11
    btnPartNoSearch.ForeColor = Color.White
    btnPartNoSearch.BackColor = Color.Red
    btnPartNoSearch.Size = New Size(26, 23)
    btnPartNoSearch.Location = New Point(285, 26)
    btnPartNoSearch.Visible = True
    Me.Controls.Add(btnPartNoSearch)
'This creates the Panel and sets the labels and Textboxes to be displayed.
    Dim pnlOrderLine As New Panel()
    pnlOrderLine.Size = New Size(1577, 122)
    pnlOrderLine.Location = New Point(12, x)
    pnlOrderLine.BorderStyle = BorderStyle.Fixed3D
    pnlOrderLine.ForeColor = Color.White
    pnlOrderLine.Controls.Add(lblPrtNo)
    pnlOrderLine.Controls.Add(txbPartNo)
    pnlOrderLine.Controls.Add(btnPartNoSearch)

    a = a + 1
    x = x + 146

End Sub

Private Sub txbPartNo_Textchanged(ByVal sender As System.Object, ByVal e As EventArgs)
    Dim txbPartNo As TextBox = DirectCast(sender, TextBox)
    Me.Text = txbPartNo.Name & ": " & txbPartNo.Text
    txbPartNo.Show()

End Sub

繰り返しパネルを作成するときと同じ思考プロセスを使用して、次のコードを使用して、そのパネルをメイン パネルにドロップしようとしました。

' This set the order line panel within the main panel
'Adding to main panel
pnlMainPanel.Controls.Add(pnlOrderLine)
pnlMainPanel.Visible = True
'Adding to Form i.e. me
Me.Controls.Add(pnlOrderLine)

言うまでもなく、これはうまくいきません。ライン パネルは作成されますが、メイン パネルの後ろにあります。メインパネル内にそれらが必要です。

誰でもこれを行う方法を知っていますか?

事前に、ご協力いただきありがとうございます。

ドン

4

0 に答える 0