Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi Everyone,
I am using a timer to record the location of clicks I perform in a picturebox for a specified amount of time that is timed by the timer. As a next step I added PictureBox paint event to show small circles where I hit in the pictureBox. It works perfectly but timer ticks somehow becomes disabled. Next I noticed that if I comment out the following line from the FORM
C#
InitializeComponent()
function, timer starts working:

C#
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);


Hence I can use one of them at a time but unable to use both functionalities at the same time. Please help me resolve this issue.
Posted
Comments
Dave Kreskowiak 22-Feb-14 14:15pm    
It's impossible to help you because we can't see the rest of the code.

No, the Timer Tick event does NOT can "canceled" by another event. There is something very wrong with your overall design that is causing these symptoms.
Sergey Alexandrovich Kryukov 22-Feb-14 20:53pm    
Exactly. I actually provided useful advice in my answer, please see.
—SA

1 solution

Dave Kreskowiak is right, please see his comment to the question. Nothing is cancelled or disabled.

Not only handling Paint event of the PictureBox makes no sense, using PictureBox for rendering graphics makes no sense at all (even though it is possible). This is just a control designed to show some static image in a simplified way, a wrapper of an image created just for convenience. It's functionality is totally redundant. You can render graphics on your own custom control or many other controls, such as Panel.

Please see my past answers which explain pretty much everything:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

For explanation of graphics rendering in System.Windows.Forms using System.Drawing, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

—SA
 
Share this answer
 
Comments
Dave Kreskowiak 23-Feb-14 10:32am    
5
Sergey Alexandrovich Kryukov 23-Feb-14 12:18pm    
Thank you, Dave.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900