Moving Shapes on a form.

Hi guys,

I'm trying to get my head around where to begin with this, I just want suggestions on approach and am not looking for code.

Basically what I need to do is "animate" some shapes on my main form.

what I want is something similar to the old XP stuff in dialogues etc like delete where a document flies to the other side or a glow along a network cable travels left to right.

In this case I only need it to be a basic shape, say a square or a ball and want it to go left to right and back again, no fancy animation, it doesn't need to be an image, just a basic filled shape of any colour.

simple motion <--------->.

Can anybody suggest a way to go about this?

I was thinking of creating a panel within which I can use the FillEllipse() (for a circle) or similar for a square, which I assume accept arguments for position?

Any help appreciated, thanks.
I suggest you check out the MSDN GDI reference.

If you wanted a basic shape like a square or rectangle, see this link: http://msdn.microsoft.com/en-us/library/ms912947%28v=MSDN.10%29.aspx

// edit - this call takes the location parameters of the rectangle, so storing those in a variable perhaps in a loop with a bit of manipulation to them will help achieve the moving.

To make that shape filled try out CreateSolidBrush: http://msdn.microsoft.com/en-us/library/ms908187%28v=MSDN.10%29.aspx

To achieve these effects they usually have to be between a call to BeginPaint ( http://msdn.microsoft.com/en-us/library/ms908187%28v=MSDN.10%29.aspx ) & to EndPaint ( http://msdn.microsoft.com/en-us/library/aa453041%28v=MSDN.10%29.aspx ).

Hope that helps
Last edited on
Sorry, which part was the edit referring to? I have no problems with the drawing and filling part already, was just unsure which part is relevant to sorting out the movement.

Am I right in thinking that the call to the draw function will accept position vectors in the form of the standard coordinate system so ican just keep drawing it in different places each time?

Thanks so much, I appreciate the assistance.
The edit refers to the link above it.

To copy & paste the rectangle drawing function from MSDN:
1
2
3
4
5
6
7
BOOL Rectangle(
  HDC hdc, 
  int nLeftRect, 
  int nTopRect, 
  int nRightRect, 
  int nBottomRect
);


As you can see four integer parameters are taken - these paramters are described as:

nLeftRect
[in] Specifies the logical x-coordinate of the upper left corner of the rectangle.
nTopRect
[in] Specifies the logical y-coordinate of the upper left corner of the rectangle.
nRightRect
[in] Specifies the logical x-coordinate of the lower right corner of the rectangle.
nBottomRect
[in] Specifies the logical y-coordinate of the lower right corner of the rectangle.


So changing these should change the location of the rectangle.
Ah ok, im on my Android phone at the moment and couldn't get the site to load right, hence my confusion. Thanks for the c&p though. I'll try it out when I get back to my pc and let you know if I hit any snags.

Thanks again.
Update,

I got this working, so I can move my shape anywhere i want:

1. Create panel object;

Graphics^

2. Clear panel object to desired background colour;

Clear()

3. define SolidBrush;

SolidBrush^

4. Define a rectangle (as posted above)

5. Fill the rectangle;

FillRectangle()

next you just clear, update the x and y coordinates and then fill rectangle again.


Thanks for all the help guys, it was an important initial step that got me well on my way.
Topic archived. No new replies allowed.