Private Declare Function GetCursorPos Lib "user32" (lpPoint As pointapi) As Long
Private Type pointapi
X As Long
Y As Long
End Type
Private Sub Command_Click(Index As Integer)
Text3.Text = 1
End Sub
Private Sub Command_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index > 0 And Button = 2 Then
Unload Command(Index)
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim mouse As pointapi
GetCursorPos mouse
Text1.Text = Val(mouse.X) * 15 - Me.Left - 50
Text2.Text = Val(mouse.Y) * 15 - Me.Top - 300
If Text1.Text > 1000 Then
If Text3.Text = 1 Then
If Button = 1 Then
i = Command.UBound + 1
Load Command(i)
Command(i).Left = Text1.Text
Command(i).Top = Text2.Text
Command(i).Caption = Str(i)
Command(i).Visible = True
End If
End If
If Text3.Text = 2 Then
If Button = 1 Then
i = Label.UBound + 1
Load Label(i)
Label(i).Left = Text1.Text
Label(i).Top = Text2.Text
Label(i).Caption = Str(i)
Label(i).Visible = True
End If
End If
If Text3.Text = 3 Then
If Button = 1 Then
i = Text.UBound + 1
Load Text(i)
Text(i).Left = Text1.Text
Text(i).Top = Text2.Text
Text(i).Visible = True
End If
End If
End If
End Sub
Private Sub Label_Click(Index As Integer)
Text3.Text = 2
End Sub
Private Sub Label_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index > 0 And Button = 2 Then
Unload Label(Index)
End If
End Sub
Private Sub Text_Click(Index As Integer)
Text3.Text = 3
End Sub
Private Sub Text_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index > 0 And Button = 2 Then
Unload Text(Index)
End If
End Sub
无法在窗体上添加控件是为什么
小弟明白,但是我上面的程序错在什么地方,无法显示控件啊,谢谢!
用 Controls.Remove(控件) 动态删除控件。注意:在VB中只能动态删除那些动态添加的控件;不允许删除在窗体设计器上布置的控件!
示例如下:
(1)创建一个VB工程
(2)在Form1上布置两个Command
(3)窗体代码
Option Explicit(4)运行
窗体启动
点击“添加控件”按钮
点击“删除控件”按钮