Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET WinForm
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 3:54am
Edited 27-Dec-11 4: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 Maciej Los 495
1 Sergey Alexandrovich Kryukov 469
2 OriginalGriff 360
3 Sascha Lefévre 255
4 Abhinav S 250
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076

Advertise | Privacy | Mobile
Web04 | 2.8.150327.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