views:

229

answers:

3

It is my understanding and experience that VB.NET does not perform well with moving graphics from point A to point B in a form.

How do I draw a rectangle or a line and move it from point A to point B?

Is there a reliable way to do this without seeing a black rectangle around the moving object on every frame? I've tried this with bitmaps before but it doesn't work. I see the frame rendering and it's way to slow.

Perhaps there is an animation Control or library?

Thanks.

A: 

You could use WPF. Even if you using WinForms you can interop with a WPF user control using the ElementHost control

rip
How would that help?
Moshe
+1  A: 

First, I would not blame VB.Net. Both C# and VB.Net use the same graphics api (GDI+). Here is an example I found and I believe it will help you to understand what needs to be done.

VB Helper

Wade73
+1. I guess you are right. What alternatives are there to GDI+? Is there a way to implement Dirrect X, or is that even going in the right direction?
Moshe
You can use DirectX from VB.Net, but I have never done it myself. WPF is another option - http://windowsclient.net/WPF/.
Wade73
+1  A: 

I'm not going to provide a full example here, as I'm more used to C#, but here is pseudo code for how I'd do it.

function paint()
    draw line (x, y, x + xEnd, y + yEnd)      // Use the graphics object here.
end

function update()
    update x
    update y
end

Something must be called, either every frame or every time you have an event (key press etc...). This updates the x, and y cooridinates of the line respectively. GDI+ would be used for drawing the line, in other words the built in graphics library is more than enough for simple drawings.

This could be improved by using vectors (2D) to represent the line coordinates, rather than standard data types for individual x and y coordinates.

Finglas
If you post it in c#, I'd appreciate it. I have enough general programming experience to work it out from there.
Moshe