Click to See Complete Forum and Search --> : timer and drawing


ChayKieu
February 16th, 2009, 07:58 PM
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.


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

BigEd781
February 16th, 2009, 08:02 PM
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.

ChayKieu
February 16th, 2009, 08:08 PM
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. :)

Thu
February 16th, 2009, 08:40 PM
.... 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.

BigEd781
February 16th, 2009, 09:11 PM
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.

Khiem
February 16th, 2009, 09:19 PM
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

k_nemelka
February 17th, 2009, 06:14 PM
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!

cjard
February 17th, 2009, 06:55 PM
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) ?