Moving text around on a PictureBox object?

CrazySchmidt
01-25-2005, 04:39 PM
I am wanting to move text from one position in a "PictureBox" to another by seemingly clicking and dragging and having the text appear to be moving along with the mouse pointer.

The text is introduced by the "PictureBox.Print" method. I have tried using the "vbInvert" with the "PictureBox" "DrawMethod" as you would do with lines and circles on the mouse move event, but this doesn't seem to work with fonts as I get a trail of text all over the screen! :chuckle:

At the moment I have worked around this by using a rectangle that represents the boundary of the text in question which is functional but I would like to advance this is possible.

Does anyone have a solution for this?

Thanks in advance, CrazySchmidt. :)

passel
01-25-2005, 05:53 PM
Yes, the raster Ops do not apply to Printed Text. If you use the API to draw the text
they would probably not apply as well.

My first thought, would be to print to a hidden picturebox, with AutoRedraw set True of course,
and then use bitblt to copy the text to the visible picturebox.

A second approach would be to have AutoRedraw set True when you do all your
permanent drawing or printing, but set it to False when you need to drag something
around. You can then print your text, and then when it needs to be moved, use cls
(or show and hide a shape control or label to clear a small area) and then reprint the
text. The cls will not clear the "permanent" drawing, on the stuff drawn while AutoRedraw is False.

A third idea, use a labelbox contained in the picturebox. Set the caption to your text,
and drag it around the picturebox (BackStyle set to Transparent).
Hide the label (printing your text in the picturebox), once it's in it's new location.
Third approach could be flashy. Not sure how flashy the second idea would be
(having AutoRdraw set True could cut down on the flashiness of the second method).

Assuming the Scalemode of the picturebox was left at the default vbTwips
then code like this could be use to move a label on a picturebox.

Option Explicit
Dim lx As Single, ly As Single
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lx = X: ly = Y
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label1.Left = Label1.Left + (X - lx)
Label1.Top = Label1.Top + (Y - ly)
End If
End Sub


or this

Option Explicit

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lx As Single, ly As Single
If Button = 1 Then
Label1.Left = Label1.Left + (X - lx)
Label1.Top = Label1.Top + (Y - ly)
Else
lx = X: ly = Y
End If
End Sub


If the Scalemode was not twips then temporarily set it to twips in the MouseMove
of use a scalefactor based on Screen.TwipsPerPixelX and Y, or use ScaleX and Y, to convert the label's X and Y (which are always in twips) to the Scale
of the picturebox.

Example of the second approach

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.AutoRedraw = False
Picture1.CurrentX = X: Picture1.CurrentY = Y
Picture1.Print "Hello There" 'temporary
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.Cls 'erase tempoary
Picture1.CurrentX = X
Picture1.CurrentY = Y
Picture1.Print "Hello There" 'move temporary
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.AutoRedraw = True
Picture1.CurrentX = X
Picture1.CurrentY = Y
Picture1.Print "Hello There" 'make it permanent
End Sub

CrazySchmidt
01-25-2005, 07:23 PM
Hi passel, option 2 works perfectly for what I am doing, it makes the app look that bit smarter. :cool:

Many thanks for your help.

Cheers, CrazySchmidt. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum