Click here to Skip to main content
Rate this: bad
good
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
Un_NaMeD1.4K
Edited 27-Dec-11 4:45am
v2
Rate this: bad
good
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.
 
[EDIT]
 
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
  Permalink  
v2
Comments
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.
--SA
Rate this: bad
good
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.
  Permalink  
Comments
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.
--SA

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2014
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