Moving Rectangle within a PictureBox Control

F

fripper

I am a real novice when it comes to the graphics class in VB 2005. I have a
windows app with a large picture box control with a black background ...
except for a small rectangle that has an image in it. A timer fires every
second or so and when it does I want to move the small rectangle within the
picture box to another location within the picture box. I don't want to
copy the rectangle ... I want to move it and have the vacated rectangle
revert to the black background. Now, this program is an upgraded version of
a VB .Net 2003 version I had written. In that version I used the bitblt
function to move this box but, as is so often the case, that function is not
supported in VB 2005. Can someone help me understand how to move a junk of
the screen from one location to another? I would appreciate whatever
specificity you can provide ... I really am a novice!

Thanks.
 
A

Armin Zingler

fripper said:
I am a real novice when it comes to the graphics class in VB 2005. I have
a windows app with a large picture box control with a black
background ... except for a small rectangle that has an image in it.
A timer fires every second or so and when it does I want to move
the small rectangle within the picture box to another location
within the picture box. I don't want to copy the rectangle ... I
want to move it and have the vacated rectangle revert to the black
background. Now, this program is an upgraded version of a VB .Net
2003 version I had written. In that version I used the bitblt
function to move this box but, as is so often the case, that
function is not supported in VB 2005.

What does "not supported" mean?
Can someone help me
understand how to move a junk of the screen from one location to
another? I would appreciate whatever specificity you can provide
... I really am a novice!

The usual way is to repaint everything, including the rectangle at the new
position. The first, simplest way is to paint in the Picturebox' Paint
event. Call it's Invalidate method to trigger the Paint event in the Timer's
Tick event.


Armin
 
G

Guest

Why would you think bitblt is not supported. This is a Windows API function
and has nothing to do with the .net framework. I would guess that even the
new Vista has support for the bitblt function since it is widely used as a
basis for copying, moving, etc. pixels.
 
F

fripper

The bitblt function (as I understand it) requires a device context paramater
(actually two ... one for the source and one for the destination). VB 2005
gives an error message when compiling a bitblt call with, say, picPic1.hdc,
as the source device context parameter. According to the VB 2005
documentation device contexts are no longer necessary with GDI+. So the
question remains ... How do I copy picPic1 to picPic2 using bitblt?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top