Re: Move images and text on form?



Mike,

I'm trying to work this out but the next Question would be if the image
can also have a transparent background since that takes the most space
on the form...

and for this one:
should the Label1 have its Index set to 0 as well?

Marco

Mike Williams schreef:

"vonClausowitz" <vonclausowitz@xxxxxxxxx> wrote in message
news:1156083627.272601.154900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So would that be easy with the code I have at the moment
or would I have to start from scratch?

You wouldn't have to start from scratch, but you would have to change all
the code that loads and uses picture boxes for the icons you are positioning
and dragging around so that you generate and use sprites instead, which
would of course take a bit of time. It would be a good exercise though. The
code that Larry posted a link to should be fairly easy for you to convert.
Alternatively, if you want to keep more or less the same code that you
currently have (as far as the picture boxes is concerned) then you could use
a transparent Label instead of printing the text into the picture and drag
the Label around in synch with the Picture Box. If your icon image is
rectangular and does not itself need to have transparent areas then that
might be the easiest method for you? Try the following example on a new VB
Form containing one small picture box and one label control:

Mike

Option Explicit
Private dragging As Boolean
Private xpos As Single, ypos As Single
Private xmouse As Single, ymouse As Single
Private xOffset As Single, yOffset As Single

Private Sub Form_Load()
' draw a test background
Dim n As Long
Me.AutoRedraw = True
Me.ScaleMode = vbTwips
For n = 100 To Me.ScaleWidth / 2 Step 200
Me.Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), n, Rnd * &HFFFFFF
Next n
Picture1.ScaleMode = Me.ScaleMode
Picture1.BorderStyle = vbBSNone
Picture1.BackColor = vbCyan
Label1.AutoSize = True
Label1.BackStyle = vbTransparent
Label1.Alignment = 2
Label1.Caption = "Test" & vbCrLf & "Message"
Label1.Left = Picture1.Left + _
(Picture1.Width - Label1.Width) / 2
Label1.Top = Picture1.Top + Picture1.Height
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
xmouse = X
ymouse = Y
xOffset = Picture1.Left - Label1.Left
yOffset = Picture1.Top - Label1.Top
dragging = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Dim x1 As Single, y1 As Single
If dragging Then
x1 = Picture1.Left + X - xmouse
y1 = Picture1.Top + Y - ymouse
If (Picture1.Left <> x1) Or (Picture1.Top <> y1) Then
Picture1.Move x1, y1
Label1.Move x1 - xOffset, y1 - yOffset
End If
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
dragging = False
End Sub

.


Loading