Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a list box and some images in the listbox.
Now i display the image on a canvas and draw a shape like rectangle with mouse down , mouse move and mouse up events.and want to copy the rectangle on all the images, so i have taken a list with the center point of the rectangle and for each image i have drawn a shape with the centre point of the first rectangle.
now when i click on each image in the listbox. the old rectangle will be hidden and new rectangle is created with the centre point on that image.
well up to this is OK.

Now i want to generate mouse click event on the shape(these are dynamically created) on every image

Listbox selection changed:

CSS
Rectangle rect1=new Rectangle {
                                    Stroke=Brushes .Black ,
                                    StrokeThickness=1};
rect1.Height=Myrect.Height;
rect1.Width=Myrect.Width;
     Canvas.SetLeft(rect1,Hlist.Position.X-rect1.Width/2);
     Canvas.SetTop(rect1,Hlist.Position.Y-rect1.Height/2);
Mycanvas.Children.Add(rect1);
rect1.MouseRightButtonDown+=new MouseButtonEventHandler(Rect1_Click);// this event is not raising



Every time when listbox image selection is changed one shape is created. now where should i write the mouse click event for the shape created.

Thanks,
Posted
Updated 1-Nov-11 22:24pm
v4
Comments
BobJanova 28-Oct-11 8:35am    
What is the question? The commented out line should do what you want, I think.
VK k 28-Oct-11 9:16am    
even though if i remove the commented out line the event is not raised..

As I see in your code, you create new Rectangle (rect1) that is initiated with the values of another Rectangle (MyRect). You register the event to rect1 but, the Rectangle that you add to MyCanvas is MyRect.


It looks like you meant to add rect1 to the canvas instead of MyRect...

 
Share this answer
 
Comments
VK k 2-Nov-11 4:28am    
I have tried in this way but its not generating any event.
when we click on the rect1 shape listbox selection change event is not firing and the rect1 and the event is in selection changed event only.
Shmuel Zang 2-Nov-11 5:14am    
Ok. I saw that you fixed your question, according to this solution.
Which event isn't fired (The Rect1_Click event-handler, the SelectionChanged event of the list or, the both of them)?
VK k 2-Nov-11 6:19am    
Rect1_Click event is not firing..
Shmuel Zang 2-Nov-11 8:16am    
Maybe you registered the event-handler to the wrong event. See my 2nd solution.

The Click operation is usually performed by the left mouse button. Why do you use the MouseRightButtonDown event? It seems like you have to use the MouseLeftButtonDown event instead.

 
Share this answer
 
 
Share this answer
 

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