模块中动态添加控件并执行事情——陷入混乱中,请高人指点,高分求教,标题长,求点击
Module Module1
Dim WithEvents Tb1 As New Label
Dim i As Integer
Public Sub creat1() '动态添加控件过程
Tb1.BorderStyle = BorderStyle.Fixed3D
Dim labelname As Boolean
labelname = printyl.ControlCollection.Equals(Tb1.Name, Tb1.Name)
If labelname = True Then
i = i + 1
Tb1.Location = New System.Drawing.Point(100 + i, 100 + i)
Tb1.Name = "ttss" + CStr(i)
Tb1.Text = "ttss" + CStr(i)
End If
Tb1.Size = New System.Drawing.Size(200, 100)
printyl.Controls.Add(Tb1)
End Sub
Dim ss As Boolean
Dim mov As Point
Private Sub Tb1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Tb1.MouseMove
If ss = True Then
Dim a, b As Integer
a = mov.X - e.X
b = mov.Y - e.Y
Tb1.Location = New Point(Tb1.Location.X - a, Tb1.Location.Y - b)
ElseIf ss = False Then
Tb1.Location = New Point(Tb1.Location.X, Tb1.Location.Y)
End If
End Sub
Private Sub Tb1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Tb1.MouseDown
ss = True
mov = New Point(e.X, e.Y)
End Sub
Private Sub Tb1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Tb1.MouseUp
ss = False
End Sub
不知道是那个地方弄错了,实在不会写,麻烦指导~~
另外当把 Tb1 as New label 写在 Public Sub creat1() 里面时,可以得到上面label累积出现的效果(例:label1、label2、label3....),但是这样出现的所有label又都不能执行下面的事件,用了 AddHandler XX.MouseMove, AddressOf XX_MouseMove 这个也不行,不知道是不是没用对。
总之现在的效果就是两者只能实现一种,要么累积出现label,但都不能执行事件,要么出一个新label,上一个消失,但可以执行事件
郁闷快哭了~~~
[最优解释]
顶顶~~~