vb中如何动态添加删除控件

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

vb中如何动态添加删除控件

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 S 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

无法在窗体上添加控件是为什么

问题补充:

小弟明白,但是我上面的程序错在什么地方,无法显示控件啊,谢谢

推荐答案

Private Sub Form_Load()

Form1.Controls.Add "mandButton", "cmdObj1", Frame1

With Form1!cmdObj1

.Visible = True

.Width = 2000

.Caption = "Dynamic Button"

End With

End Sub

其他回答共1条

动态添加控件有两种方法,一种是添加一个控件,一种是再已存在的控件组里动态添加组员。

法1:dim withevents CMD as commandbutton

set CMD=controls.add(""mandbutton","CMD1")

相关文档
最新文档