注册 登录
编程论坛 VB6论坛

VB6.0中,如何动态添加控件至指定的PictureBox控件中?

小刀神 发布于 2018-06-25 15:29, 1681 次点击
VB6.0中,如何动态添加控件至指定的PictureBox控件中?
顺便问问,当PictureBox控件中添加的控件达到一个量的时候,如何让PictureBox控件出现滚动条的东西,以便动态显示这些控件?
1 回复
#2
wufuzhang2018-06-26 14:04
大概思路,先创建控件数组的第一个控件(如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
只有本站会员才能查看附件,请 登录
1