Click here to Skip to main content
11,813,974 members (41,552 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET
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...
Posted 27-Dec-11 2:54am
Edited 27-Dec-11 3:45am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^],
Control events not firing after enable disable + multithreading[^].

Un_NaMeD at 28-Dec-11 4:27am
Thank you SA.
Threading helped much, but I don't get why you hate picturebox that much :)
Whatever, thank you again...
SAKryukov at 28-Dec-11 17:59pm
I don't hate it at all; it might be used in some situations; it's a pure practical comparison -- if you have to implementations, the one which is more redundant and less supportable should go. Again, it depends on situation.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You don't "draw" to a PictureBox. You draw to a Bitmap, and display the bitmap in the PictureBox.
Un_NaMeD at 27-Dec-11 9:06am
Sorry for my bad English..
Un_NaMeD at 27-Dec-11 9:20am
Any suggestion you have?
That was my suggestion - draw to a bitmap and display the bitmap in the PictureBox. I also suggest that you refrain from voting 1 on people that are helping you. It doesn't promoite the desire to continue helping.
RaisKazi at 27-Dec-11 10:29am
My 5 to counter down-vote.
SAKryukov at 27-Dec-11 15:07pm
I voted 5, too, but chances are, even PictureBox can be redundant. Please see my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 265
1 Maciej Los 203
2 Palash Mondal_ 190
3 Sergey Alexandrovich Kryukov 179
0 OriginalGriff 3,877
1 KrunalRohit 2,526
2 Maciej Los 2,245
3 CPallini 2,240
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100