首页 > 解决方案 > 基于 GridView 创建 Panels

问题描述

我正在制作一个应用程序,其中有必要创建一个包含多个选项的列表,在这种情况下,该列表包括项目的度量及其位置。位置是指在一个面板中,有位置 A、B、C、D,并且每个项目必须占据 GridView 列表中标记的这些位置之一。

应该如下。

面板和 GridView

我创建了一个代码,但没有与 GridView 连接,并根据在 gridview 中创建的单元数创建对象。

 For i = 1 To ContadorIzq

            pos = CInt(TextBox38.Text)
            poslabel = CInt(TextBox42.Text)

            Dim pb As New Panel With
            {
                .Width = 120,
                .Height = 460,
                .Top = 10,
                .Left = 10,
                .BorderStyle = BorderStyle.FixedSingle,
                .BackgroundImage = Image.FromFile("C:\Images\sections\Ejem.bmp"),
                .BackgroundImageLayout = ImageLayout.Stretch,
                .ContextMenuStrip = CntxtMnuStrpUnit,
                .Name = "Panel" & CInt(TextBox37.Text),
                .Location = New Point(pos, 20)
            }

            AddHandler pb.Click, AddressOf myClickHandler_b

            Dim labela As New Label With {
                .AutoSize = True,
                .Location = New Point((poslabel), 12),
                .Text = "Section " & CInt(TextBox37.Text),
                .ForeColor = Color.White,
                .BackColor = Color.Transparent,
                .Font = New Font(Me.Font, FontStyle.Bold),
                .Name = "Label" & CInt(TextBox37.Text)
            }

            AddHandler labela.Click, AddressOf myClickHandler

            labela.Font = New Font(labela.Font, FontStyle.Bold)

            Panel1.Controls.Add(pb)
            pb.Controls.Add(labela)

            Dim posY As Int16 = 30
            Dim posX As Int16 = 3

            For j = 1 To 4

                If j = 1 Then

                    Dim pbdoors As New Panel With {
                        .Width = 114,
                        .Height = 198,
                        .Top = 10,
                        .Left = 10,
                        .BorderStyle = BorderStyle.FixedSingle,
                        .BackgroundImage = Image.FromFile("C:\Images\Doors\EjemB.bmp"),
                        .BackgroundImageLayout = ImageLayout.Stretch,
                        .ContextMenuStrip = CntxtMnuStrpUnit,
                        .Name = "Panel" & CInt(TextBox37.Text) & j
                    }

                    AddHandler pbdoors.Click, AddressOf myClickHandler_doors

                    pbdoors.Location = New Point(posX, 30)
                    pb.Controls.Add(pbdoors)
                    posY = (posY + 100)

                ElseIf j = 2 Then

                    posY = 130

                ElseIf j = 3 Then

                    Dim pbdoors As New Panel With {
                        .Width = 114,
                        .Height = 98,
                        .Top = 10,
                        .Left = 10,
                        .BorderStyle = BorderStyle.FixedSingle,
                        .BackgroundImage = Image.FromFile("C:\Images\Doors\EjemC.bmp"),
                        .BackgroundImageLayout = ImageLayout.Stretch,
                        .ContextMenuStrip = CntxtMnuStrpUnit,
                        .Name = "Panel" & CInt(TextBox37.Text) & j
                    }

                    AddHandler pbdoors.Click, AddressOf myClickHandler_doors

                    pbdoors.Location = New Point(posX, 230)
                    pb.Controls.Add(pbdoors)
                    posY = (posY + 100)

                ElseIf j = 4 Then

                    Dim pbdoors As New Panel With {
                        .Width = 114,
                        .Height = 98,
                        .Top = 10,
                        .Left = 10,
                        .BorderStyle = BorderStyle.FixedSingle,
                        .BackgroundImage = Image.FromFile("C:\Images\Doors\EjemC2.bmp"),
                        .BackgroundImageLayout = ImageLayout.Stretch,
                        .ContextMenuStrip = CntxtMnuStrpUnit,
                        .Name = "Panel" & CInt(TextBox37.Text) & j
                    }

                    AddHandler pbdoors.Click, AddressOf myClickHandler_doors

                    pbdoors.Location = New Point(posX, 330)
                    pb.Controls.Add(pbdoors)
                    posY = (posY + 100)

                End If

            Next

            TextBox38.Text = pos + 120
            TextBox37.Text = CInt(TextBox37.Text) + 1
            TextBox40.Text = CInt(TextBox40.Text) + 120

        Next

拜托,有什么想法吗?,你能帮帮我吗?

标签: vb.netwinformsgridviewpanel

解决方案


推荐阅读