|
-
February 16th, 2009, 08:58 PM
#1
timer and drawing
I have a timer that will be used to draw an image
The interval is 3 seconds, In the OnPaint() I will change the coordinates of the rectangle I draw
when I run the program it just doesn't work.
Code:
Timer timer=null;
int x;
int y;
private void Func()
{
timer=new Timer();
x=1;
y=2;
timer.Tick+=new EventHandle(timer_Tick)
}
protected void timer_Tick(EventArg a)
{
}
protected overide void Onpain(PaintEvetArg e)
{
Graphics g=e.grahics;
g.drawRectanfgle(brush,x,y,12,12)
x++;
y++;
}
Thanks
-
February 16th, 2009, 09:02 PM
#2
Re: timer and drawing
You should awlays state what you have tried and what specifically is not working. You are not doing anything in your Timer.Tick handler, so what would you expect? You are simply incrementing x and y in OnPaint, the timer is useless. You have to call Start() on your timer and then change the x and y coordinates in the Tick handler. You will also need to set the interval on the timer. You will want to call Invalidate() on your control after changing the x and y in the Tick handler.
-
February 16th, 2009, 09:08 PM
#3
Re: timer and drawing
Thanks a lot,
I will stick with only the narrow sense at most I could figure out your explanation.
I am sorry for my bad English used by the way.
-
February 16th, 2009, 09:40 PM
#4
Re: timer and drawing
 Originally Posted by BigEd781
.... You are not doing anything in your Timer.Tick handler, so what would you expect? You are simply incrementing x and y in OnPaint, the timer is useless...
It might not be related to how a timer will work, if you already have the control.
Sometimes it is just a flip of true and false to completely disable properties.
-
February 16th, 2009, 10:11 PM
#5
Re: timer and drawing
 Originally Posted by Thu
It might not be related to how a timer will work, if you already have the control.
Sometimes it is just a flip of true and false to completely disable properties.
I don't understand that at all...
He wants to update the rectangle location using the Timer, but the Timer is not doing anything. It is not even started.
-
February 16th, 2009, 10:19 PM
#6
Re: timer and drawing
 Originally Posted by BigEd781
I don't understand that at all...
He wants to update the rectangle location using the Timer, but the Timer is not doing anything. It is not even started.
Most students in my class has it as spring exercise alreay over, I need him to return only the lost papers, which doesn't cost him much. No more further discussion of solution is kindly requested
Thanks and Regards
hi,,,
-
February 17th, 2009, 07:14 PM
#7
Re: timer and drawing
 Originally Posted by Khiem
Most students in my class has it as spring exercise alreay over, I need him to return only the lost papers, which doesn't cost him much. No more further discussion of solution is kindly requested
Thanks and Regards
That, I believe, is the most bizarre statement I have ever read on this board!
-
February 17th, 2009, 07:55 PM
#8
Re: timer and drawing
Is it guaranteed that the thread the timer uses to handle the tick is the thread that created the graphics? If not, might there be a windows GUI cross threading problem (in addition to the fact that the timer is inactive, and the handler code does nothing) ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|