Click here to Skip to main content
11,632,104 members (76,566 online)
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 2:54am
Un_NaMeD1.4K
Edited 27-Dec-11 3: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 8,498
1 Sergey Alexandrovich Kryukov 8,149
2 Mika Wendelius 6,260
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 1,995


Advertise | Privacy | Mobile
Web02 | 2.8.150728.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