求高手解答!VB程序设计题:动态增减控件 设计程序,当鼠标单击窗体的任意位置时,在该位置出现一个控件, 10

 我来答
plfushicn
2011-06-05 · 超过24用户采纳过TA的回答
知道答主
回答量:94
采纳率:0%
帮助的人:37.4万
展开全部
Option Explicit
Private WithEvents NewButton As CommandButton
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮

Private Sub Command1_Click()
If NewButton Is Nothing Then
Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Form1)
'增加新的按钮cmdNew
NewButton.Move Command1.Left + Command1.Width + 240, Command1.Top
'确定新增按钮cmdNew的位置
NewButton.Caption = "动态添加的按钮"
NewButton.Visible = True
'显示该按钮
End If
End Sub

Private Sub Command2_Click()
If NewButton Is Nothing Then
Exit Sub
Else
Controls.Remove NewButton
Set NewButton = Nothing
End If
End Sub
Private Sub NewButton_click()
MsgBox "这是动态增加的按钮,你可以单击“删除控件”按钮删除它", vbDefaultButton1, "Click"
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友bdb9803
2011-06-05 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:1亿
展开全部
'窗体上放一个command按钮控件,设置index属性=0
Private Sub Form_Load()
Command1(0).Visible = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static i As Long
i = i + 1
Load Command1(i)
Command1(i).Visible = True
Command1(i).Move X, Y
End Sub
追问
设计程序,当鼠标单击窗体的任意位置时,在该位置出现一个控件,并要求控件标题显示出单击该控件的次数;当单击已出现的控件时,该控件消失。x谢谢啦~真的真的非常感谢~
追答
'窗体上放一个command按钮控件,设置index属性=0

Private Sub Command1_Click(Index As Integer)
Unload Command1(Index)
End Sub

Private Sub Form_Load()
Command1(0).Visible = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static i As Long
i = i + 1
Load Command1(i)
Command1(i).Visible = True
Command1(i).Move X, Y
Command1(i).Caption = i
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
一只KK啊
2011-06-05 · TA获得超过162个赞
知道小有建树答主
回答量:175
采纳率:100%
帮助的人:75.2万
展开全部
用CreatObject来创建控件对象

或者你先放好,通过点击事件来控制Visible属性
追问
嗯,具体一点呗,具体的程序代码,我不太懂哎
谢啦~
追答
我只提供思路,不提供代码
代码书写这些知识是你自己应该具备的
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式