Tom Glenn
By: a guest | Feb 8th, 2010 | Syntax:
C# | Size: 1.28 KB | Hits: 47 | Expires: Never
public void MouseLeftButtonReleased(object sender, MouseButtonEventArgs e)
{
// If we are adding a line
if(Mode == Mode.Add && selectedObject != null)
{
// Get the width of the line
var line = (LineElement)selectedObject;
var lineWidth = line.Line.X2 - line.Line.X1;
var lineHeight = line.Line.Y2 - line.Line.Y1;
// If the line width is negative, flip the X positions and reposition the control
if (lineWidth < 0)
{
// Invert the X positions so that X2 now becomes 0 and X1 now becomes the right side of the control
line.Line.X1 = Math.Abs(lineWidth);
line.Line.X2 = 0;
// Move the control to the left so that it matches where it was before
line.SetValue(Canvas.LeftProperty, (double)line.GetValue(Canvas.LeftProperty) - Math.Abs(lineWidth));
}
// If the line height is negative, flip the Y positions and reposition the control
if (lineHeight < 0)
{
// Invert the Y positions so that Y2 now becomes 0 and Y2 now becomes the top of the control
line.Line.Y1 = Math.Abs(lineHeight);
line.Line.Y2 = 0;
// Move the control up so that it matches where it was before
line.SetValue(Canvas.TopProperty, (double)line.GetValue(Canvas.TopProperty) - Math.Abs(lineHeight));
}
}