Aymann Blal

Aymann Blal

  • NA
  • 4
  • 455

Rectangle rotate once at MouseRightButtonDown

Dec 5 2019 5:34 AM

Hi all,

I need your help with this issue i have been struggling for the past days. I want to rotate a rectangle at an angle of 30° everytime i press the rightClickButton.

It works fine when i click once on the rightClickButton.But when i want to click again it doesnt rotate anymore.

It's the same behavior with MouseButtonEventHandler or without.

Can you guys help me ??

Thanks in advance.

  1. private void Rectangle_MouseRightButtonDown(object sender, MouseButtonEventArgs e)  
  2. {  
  3. MouseButtonEventHandlerRightClick(sender, e);  
  4. }  
  5. private void MouseButtonEventHandlerRightClick(object sender, MouseButtonEventArgs e)  
  6. {  
  7. element = (Rectangle)sender;  
  8. if (Mouse.RightButton == MouseButtonState.Pressed)  
  9. {  
  10. Console.WriteLine("has cliqued right");  
  11. anc_width = element.Width;  
  12. anc_height = element.Height;  
  13. i += 1;  
  14. Console.WriteLine("before transform of guantanamera");  
  15. double angle = 30;  
  16. RotateTransform rotateTransform2 = new RotateTransform(angle);  
  17. rotateTransform2.CenterX = element.Width / 2;  
  18. rotateTransform2.CenterY = element.Height / 2;  
  19. // Console.WriteLine(element.Width / 2 + " toto "+ element.Height/2);  
  20. element.RenderTransform = rotateTransform2;  
  21. /* Canvas.SetLeft(element, Canvas.GetLeft(element)+40); 
  22. Canvas.SetTop(element, Canvas.GetTop(element));*/  
  23. }  
  24. else  
  25. {  
  26. Console.WriteLine("Releasing Element");  
  27. element = null;  
  28. }  
  29. } 

Answers (1)