如何在PictureBox中以一定的间隔绘制椭圆 [英] How to Draw ellipses with an interval into PictureBox

查看:85
本文介绍了如何在PictureBox中以一定的间隔绘制椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我想使用椭圆进行简单的模拟.在用户界面中,将有一个按钮.用户将按下按钮,然后以1秒的间隔将椭圆绘制到pictureBox.像红绿灯一样...

我想我需要使用Timer Event,但是如何实现呢?

最好的问候...

Hey everyone.

I want to make a simple simulation using ellipses. In user interface, there will be a button. User will press the button, then with 1 second interval, ellipses will be drawn to pictureBox. Like a traffic light...

I guess I need to use Timer Event, but How can I achieve it?

My best regards...

推荐答案

滥用PictureBox是常见的错误.对于恒定画面的简单静态表示(或有时更改),这很有益,仅此而已.与从System.Windows.Forms.Control派生的自定义控件相比,当您尝试将其用于任何动态,交互或动画的操作时,它变得无济于事,而是实现麻烦和无用的资源消耗者.
在这里,我解释了怎么做:如何我要从旧图纸上清除面板吗? [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

—SA
It''s a common mistake to abuse PictureBox. It''s good for a simple static presentation of a constant picture (or changing sometimes), nothing else. When you try to use it for anything dynamic, interactive or animated, it becomes not help but a hassle for implementation and a useless resource-eater, compared to a custom control derived from System.Windows.Forms.Control.

Here, I explain what to do instead: How do I clear a panel from old drawing[^].

However, if you need a one-time rendering of your ellipses, do what John advised to do, it will work fine.



Oh, sorry, I did not see: a timer event. No, not, certainly no PictureBox!
And avoid using timer; using a separate thread is much better: more reliable, easier to implement and maintain.

Please see my collection of the references to my past solutions of threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


您不会绘制"到PictureBox.绘制到Bitmap,并在PictureBox中显示位图.
You don''t "draw" to a PictureBox. You draw to a Bitmap, and display the bitmap in the PictureBox.


这篇关于如何在PictureBox中以一定的间隔绘制椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆