当前位置: 首页 > 工具软件 > CanvasText > 使用案例 >

WPF C# Canvas上绘制文字

夹谷辰沛
2023-12-01
 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);

 

 类似资料: