Ok this is what I am understanding:
you have a form with a large background picture (form.backgroundimage) and you have a picture box on top of that with a smaller picture loaded (picturebox.image)
your goal is to move the picturebox around the form when the user moves the mouse, like an oversized specialized mouse cursor, correct? So you are using an image and picturebox with transparency because you don't want the user to see the borders of the picturebox, just the image floating around the background scene, right?
let me know. Is that what you are trying to do?
If so, that method is pretty processor intense, and it may be pretty difficult to get rid of the flickering. However, I think I have
an alternative that accomplishes the same goal with no fliker (or a little bit of flicker if your background image is larger than 8192 x 8192 pixles)
If not, then nevermind. I misunderstood.
P.S. What version of vb.net are you using?
- Public Class Form1
-
Private f_bmpButterfly As Bitmap
-
-
'THIS CODE ASSUMES YOU HAVE A FORM (NAMED Form1) CONTAINING A PICTUREBOX (NAMED PictureBox1)
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
' Load the background image
-
PictureBox1.BackgroundImage = New Bitmap("C:\your_background.jpg")
-
PictureBox1.Dock = DockStyle.Fill
-
PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
-
-
' load the foreground image
-
f_bmpButterfly = New Bitmap("C:\your_foreground.png")
-
-
'Do not load any image into the foreground (PictureBox1.Image) yet.
-
'the MouseMove event will do that as soon as the user moves the cursor
-
'over the picturebox
-
End Sub
-
-
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
-
'get rid of the previous foreground image
-
If Not IsNothing(PictureBox1.Image) Then
-
PictureBox1.Image.Dispose()
-
PictureBox1.Image = Nothing
-
End If
-
-
'Prepare a new, blank foreground image.
-
' By making the foreground image as small as possible (no larger than the butterfly + it's position
-
' the program doesn't have to think about any unneccessary areas of the image when displaying it.
-
Dim newBitmap As New Bitmap(e.X + f_bmpButterfly.Width, e.Y + f_bmpButterfly.Height, Imaging.PixelFormat.Format32bppArgb)
-
-
'position the butterfly in the foreground
-
' The graphics class is awesome! But don't forget to dispose of it when you're done.
-
Dim gr As Graphics
-
-
' Tell the grphics class which image you want to mess with.
-
gr = Graphics.FromImage(newBitmap)
-
-
' Paint the butterfly onto the blank foreground
-
gr.DrawImage(f_bmpButterfly, e.X, e.Y)
-
-
'Display the new foreground image. no need to change the background image
-
PictureBox1.Image = newBitmap
-
-
'Dispose ummanaged resources
-
gr.Dispose()
-
gr = Nothing
-
End Sub
-
End Class