I create program like a paint. Now a trying create standard shapes. But I have got problem with drawing rectangle. I use method DrawCore
for creating custom shapes on InkCanvas.
code:
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
if (drawingContext == null)
{
throw new ArgumentNullException("drawingContext");
}
if (null == drawingAttributes)
{
throw new ArgumentNullException("drawingAttributes");
}
DrawingAttributes originalDa = drawingAttributes.Clone();
SolidColorBrush brush = new SolidColorBrush(color);
System.Windows.Media.Pen pen = new System.Windows.Media.Pen(new SolidColorBrush(color), 1);
brush.Freeze();
drawingContext.DrawRectangle(null, pen, new Rect(GetTheLeftTopPoint(), GetTheRightBottomPoint()));
}
}
System.Windows.Point GetTheLeftTopPoint()
{
if (this.StylusPoints == null)
throw new ArgumentNullException("StylusPoints");
StylusPoint tmpPoint = new StylusPoint(double.MaxValue, double.MaxValue);
foreach (StylusPoint point in this.StylusPoints)
{
if ((point.X < tmpPoint.X) || (point.Y < tmpPoint.Y))
tmpPoint = point;
}
return tmpPoint.ToPoint();
}
System.Windows.Point GetTheRightBottomPoint()
{
if (this.StylusPoints == null)
throw new ArgumentNullException("StylusPoints");
StylusPoint tmpPoint = new StylusPoint(0, 0);
foreach (StylusPoint point in this.StylusPoints)
{
if ((point.X > tmpPoint.X) || (point.Y > tmpPoint.Y))
tmpPoint = point;
}
return tmpPoint.ToPoint();
}
But my problem is, that I can draw not all directions. that is:
How do it fix?
Thank you.