Visual Basic 2010在面板中嵌入面板

时间:2013-02-23 17:36:32

标签: visual-studio-2010 panel

在Visual Basic中(使用代码)我创建了一个包含多个标签,TextBoxes等的面板,需要在另一个面板中复制。创建重复面板的编码看起来像这样:

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)

毋庸置疑,这不起作用。线路面板已创建,但它们位于主面板后面。我在主面板中需要它们。

有人知道怎么做吗?

提前,谢谢你的帮助。

0 个答案:

没有答案