我像油漆一样创造程序。现在尝试创建标准形状。但我有绘制矩形的问题。我使用方法DrawCore
在InkCanvas上创建自定义形状。
代码:
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();
}
如何解决?
谢谢。