private void drawText(double x, double y, string text, Color color,Canvas canvasObj)
{
TextBlock textBlock = new TextBlock();
textBlock.Text = text;
textBlock.Foreground = new SolidColorBrush(color);
Canvas.SetLeft(textBlock, x);
Canvas.SetTop(textBlock, y);
canvasObj.Children.Add(textBlock);
}
使用例:
drawText(l.X1, l.Y1,"Text", Color.FromRgb(200, 0, 0), myCanvas);