I have a canvas , which have rectangles dynamically created in the code . (Around more then 100 rectangles .) I would like to have the event handling created for all the recatngles .
Instead of creating different event handling functions , I would like to have one event handling function and then , based on the rectangel which is clicked , handle the event correspondingly . I am new to this windows development .
Please sha开发者_如何学运维re some light on this .
Thanks-Best Regards, Yash
There's no built in way to do this. I've made a few tutorials to help people get started.
Let me just say that this would be easier to do in SVG if that's all you need.
In canvas there is no way to handle individually created elements inside the canvas. You can implement it programmatically. If they are just plain rectangles then may be divs are better alternative. If they can be any drawing you need to capture the mouse move events on the canvas. Find the location of mouse move event and use a formula to find if the mouse is inside any drawing or not. I have implemented same thing for polygonic shapes. All I do is that find the mouse coordinated and then check if the coordinate lies inside any shape.
精彩评论