[英]Moving Rectangle in VB?
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. 根据我的理解和经验,VB.NET不能很好地将图形从A点移动到B点的形式。
How do I draw a rectangle or a line and move it from point A to point B? 如何绘制矩形或直线并将其从A点移动到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. 谢谢。
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. 我不打算在这里提供完整的示例,因为我更习惯C#,但这是伪代码,说明了我将如何使用它。
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. 这将分别更新该行的x和y坐标。 GDI+ would be used for drawing the line, in other words the built in graphics library is more than enough for simple drawings. GDI +将用于绘制线条,换句话说,内置的图形库已足够用于简单绘图。
This could be improved by using vectors (2D) to represent the line coordinates, rather than standard data types for individual x and y coordinates. 通过使用矢量(2D)表示线坐标,而不是使用单独的x和y坐标的标准数据类型,可以改善这一点。
You could use WPF. 您可以使用WPF。 Even if you using WinForms you can interop with a WPF user control using the ElementHost control 即使您使用WinForms,也可以使用ElementHost控件与WPF用户控件互操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.