移动面板,以编程方式创建visual studio VB

时间:2014-09-18 18:56:13

标签: vb.net

我的第一篇文章......在这里: 在VB中使用Visual Studio 2012 我正在生成一个面板,为其添加6个标签,然后我想根据计时器事件将该面板移动到屏幕上。然后我想在第一个后面生成另一个面板并且它做同样的事情....添加标签并使用计时器在屏幕上移动它。

所以我有它生成面板和标签,但我不知道如何访问新创建的面板来移动它们?由于面板不在表单上,​​我的代码不会让我访问它。一旦他们完全移动屏幕,我想删除它们。这基本上会永远持续下去。     Dim count1 As Integer = 1

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    count1 = count1 + 1

    Dim Pan As Panel
    Dim Labelx As Label
    For x As Integer = 1 To 10 Step 1
        Pan = New Panel
        Pan.Name = "Panel" & Convert.ToString(x)
        Pan.Left = 300
        Pan.Top = 100 + 160 * (x - 1)
        Pan.Height = 150
        Pan.Width = 96
        Pan.BackColor = Color.Coral
        Controls.Add(Pan)

        For y As Integer = 1 To 6 Step 1
            Labelx = New Label
            Labelx.Name = "Labelx" & Convert.ToString(x)
            Labelx.Size = New System.Drawing.Size(5, 10)
            Labelx.Location = New System.Drawing.Point(0, y * 15) 'set your location
            Labelx.Text = "NEW" + Convert.ToString(y)
            Labelx.AutoSize = True
            Pan.Controls.Add(Labelx)
        Next
    Next
End Sub


'Here is an example of how I would normally move a panel, but since Panel1 doesn't exist, this code fails.

inc1 = Panel1.Location.X - convIncDiff
If inc1 > -90 Then Panel1.Location = New System.Drawing.Point(inc1, Panel1.Location.Y)

0 个答案:

没有答案