标题:VB6.0中,如何动态添加控件至指定的PictureBox控件中?
只看楼主
小刀神
Rank: 1
等 级:新手上路
帖 子:69
专家分:5
注 册:2018-5-27
结帖率:91.67%
已结贴  问题点数:10 回复次数:1 
VB6.0中,如何动态添加控件至指定的PictureBox控件中?
VB6.0中,如何动态添加控件至指定的PictureBox控件中?
顺便问问,当PictureBox控件中添加的控件达到一个量的时候,如何让PictureBox控件出现滚动条的东西,以便动态显示这些控件?
搜索更多相关主题的帖子: VB6.0 动态添加 控件 指定 PictureBox 
2018-06-25 15:29
wufuzhang
Rank: 9Rank: 9Rank: 9
来 自:广州
等 级:贵宾
威 望:21
帖 子:206
专家分:1346
注 册:2017-8-9
得分:10 
大概思路,先创建控件数组的第一个控件(如Command1(0)),然后利用Picture1_MouseDown事件,在鼠标点击
的地方加载Command1(i)控件,再利用Picture1_DragDrop事件拖动控件到合适的位置,代码如下:
程序代码:
Option Explicit
Dim ctlNum As Integer

Private Sub Form_Load()
  ctlNum = 1
End Sub

Private Sub Option1_Click(Index As Integer)
  ctlNum = Index
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim i As Integer
  If Button = 1 Then
     Select Case ctlNum
       Case 0
          i = Label1.UBound + 1
          Load Label1(i)
          Label1(i).Left = X
          Label1(i).Top = Y
          Label1(i).Height = Label1(0).Height
          Label1(i).Width = Label1(0).Width
          Label1(i).Visible = True
          Set Label1(i).Container = Picture1
       Case 1
          i = Command1.UBound + 1
          Load Command1(i)
          Command1(i).Left = X
          Command1(i).Top = Y
          Command1(i).Height = Command1(0).Height
          Command1(i).Width = Command1(0).Width
          Command1(i).Visible = True
          Set Command1(i).Container = Picture1
       Case 2
          i = Text1.UBound + 1
          Load Text1(i)
          Text1(i).Left = X
          Text1(i).Top = Y
          Text1(i).Height = Text1(0).Height
          Text1(i).Width = Text1(0).Width
          Text1(i).Visible = True
          Set Text1(i).Container = Picture1
       End Select
  End If
End Sub

Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
  Source.Move X, Y
End Sub


PS:预先创建好的控件的DragMode=1

不经历千百遍的调试,怎能体会成功时那一刹那的喜悦。
2018-06-26 14:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-488141-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018747 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved