[RESOLVED] PictureBox As Container At Run Time.

hello everyone,
i have got another strange problem. the problem is i have to use a picturebox as a container, but i can't put the controls at design time into the picturebox, controls will be added into the picturebox at Run Time.
please guide me to this way.
Real problem for me :(
[300 byte] By [chunks] at [2007-11-20 10:56:28]
# 1 Re: [RESOLVED] PictureBox As Container At Run Time.
Found this for ya:

Private Sub mnuControlsAdd_Click()
Dim index As Integer

' Create the control.
index = Text1.Count
Load Text1(index)

' Reparent the control so it's inside
' the inner PictureBox.
' SetParent Text1(index).hWnd, picInner.hWnd

' Martijn Coppoolse <vbhelper.com@martijn.coppoolse.com>
' pointed out that setting the Container is
' easier than reparenting.
Set Text1(index).Container = picInner

' Position the control.
Text1(index).Top = Text1(index - 1).Top + _
Text1(index - 1).Height + 30
Text1(index).Text = "Text1(" & Format$(index) & ")"

' Size picInner to hold the control.
picInner.Move 0, 0, _
Text1(index).Left + Text1(index).Width + 120, _
Text1(index).Top + Text1(index).Height + 120

' Display the control.
Text1(index).Visible = True

' Rearrange the scroll bars.
ArrangeScrollBars
End Sub

http://vb-helper.com/howto_new_controls_scrolled.html
dglienna at 2007-11-9 19:34:06 >
# 2 Re: [RESOLVED] PictureBox As Container At Run Time.
Thanks for help bro,
can u please try this code?
text1 is going out of the Picture when i dragg it by pressing the Right Click.

Private Sub Command2_Click()
Dim Index As Integer

' Create the control.
Index = Text1.Count
Load Text1(Index)

' Reparent the control so it's inside
' the inner PictureBox.
' SetParent Text1(index).hWnd, picInner.hWnd

' Martijn Coppoolse <vbhelper.com@martijn.coppoolse.com>
' pointed out that setting the Container is
' easier than reparenting.
Set Text1(Index).Container = picInner

' Position the control.
Text1(Index).Top = Text1(Index - 1).Top + _
Text1(Index - 1).Height + 30
Text1(Index).Text = "Text1(" & Format$(Index) & ")"

' Size picInner to hold the control.
picInner.Move 0, 0, _
Text1(Index).Left + Text1(Index).Width + 120, _
Text1(Index).Top + Text1(Index).Height + 120

' Display the control.
Text1(Index).Visible = True

' Rearrange the scroll bars.
'ArrangeScrollBars

End Sub

Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Module1.StoreX = X
Module1.StoreY = Y
End Sub

Private Sub Text1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button > 1 Then
Text1(Index).Left = Text1(Index).Left + X - Module1.StoreX
Text1(Index).Top = Text1(Index).Top + Y - Module1.StoreY
End If
End Sub
chunks at 2007-11-9 19:35:12 >
# 3 Re: [RESOLVED] PictureBox As Container At Run Time.
You could put limit checks before you actually move the control:

Private Sub Text1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim xmax%, ymax%, newx%, newy%
If Button > 1 Then
'determine maxima, minima are 0
xmax = picinner.Width - Text1(Index).Width
ymax = picinner.Height - Text1(Index).Height

'determine new expected position
newx = Text1(Index).Left + X - Module1.StoreX
newy = Text1(Index).Top + Y - Module1.StoreY

If newx >= 0 And newx <= xmax Then Text1(Index).Left = newx
If newy >= 0 And newy <= ymax Then Text1(Index).Top = newy

End If
End Sub

That's the principle. Maybe there are more elegant ways of doing it, but that shows how it works.
WoF at 2007-11-9 19:36:10 >
# 4 Re: [RESOLVED] PictureBox As Container At Run Time.
Come to think about it, this one wors even smoother:

Private Sub Text1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim xmax%, ymax%, newx%, newy%
If Button > 1 Then
'determine maxima, minima are 0
xmax = picinner.Width - Text1(Index).Width - 1
ymax = picinner.Height - Text1(Index).Height - 1

'determine new expected position
newx = Text1(Index).Left + X - Module1.StoreX
newy = Text1(Index).Top + Y - Module1.StoreY

'clip the x and y values to its limits
If newx < 0 Then newx = 0 Else If newx > xmax Then newx = xmax
If newy < 0 Then newy = 0 Else If newy > ymax Then newy = ymax

Text1(Index).Left = newx
Text1(Index).Top = newy

End If
End Sub
WoF at 2007-11-9 19:37:10 >
# 5 Re: [RESOLVED] PictureBox As Container At Run Time.
That is the great help ever, 5 Starts
chunks at 2007-11-9 19:38:15 >