Hello,
can any one give me an example how to resize and rotate the rectangle with mouse by dragging.
With the mouse events iam able to draw a rectangle on the canvas during runtime,
Now i want to resize the rectangle to desired size and able to rotate the rectangle with mouse at runtime.
C# code:
private Point startPoint;
private Rectangle rect;
under MouseLeftbuttondown:
startPoint = e.GetPosition(Canvas1);
rect = new Rectangle
{
Stroke = Brushes.Blue,
StrokeThickness = 1
};
Canvas.SetLeft(rect,startPoint.X);
Canvas.SetTop(rect,startPoint.X);
Canvas1.Children.Add(rect);
Mouse MOve:
if(e.LeftButton == MouseButtonState.Released || rect == null)
return;
var pos = e.GetPosition(Canvas1);
var x = Math.Min(pos.X, startPoint.X);
var y = Math.Min(pos.Y, startPoint.Y);
var w = Math.Max(pos.X, startPoint.X) - x;
var h = Math.Max(pos.Y, startPoint.Y) - y;
rect.Width = w;
rect.Height = h;
Canvas.SetLeft(rect, x);
Canvas.SetTop(rect, y);
MouseLeftbutton up:
rect = null;
Using this code i can draw a rectangle, How can i resize and rotate the rectangle with the mouse from code behind.
any help is much appreciated.