WPF绘制折线
WPF后台绘制折线,填充到一个GRID下
private void btnPreview_Click(object sender, RoutedEventArgs e) { GridImg.Children.Clear(); System.Drawing.Point p0 = new System.Drawing.Point(0, 0); System.Drawing.Point p1 = new System.Drawing.Point(0, 0); System.Drawing.Point p2 = new System.Drawing.Point(0, 0); System.Drawing.Point p3 = new System.Drawing.Point(0, 0); int x1 = Convert.ToInt32(txta1.Text); int y1 = Convert.ToInt32(txtb1.Text); int x2 = Convert.ToInt32(txta2.Text); int y2 = Convert.ToInt32(txtb2.Text); p0.X = 0; p0.Y = 255; p1.X = x1; p1.Y = 255 - y1; p2.X = x2; p2.Y = 255 - y2; p3.X = 255; p3.Y = 0; Line LX = new Line();//X轴 LX.X1 = 0; LX.X2 = 255; LX.Y1 = 255; LX.Y2 = 255; LX.StrokeThickness = 1; LX.Stroke = System.Windows.Media.Brushes.Black; Line LY = new Line();//Y轴 LY.X1 = 0; LY.X2 = 0; LY.Y1 = 0; LY.Y2 = 255; LY.StrokeThickness = 1; LY.Stroke = System.Windows.Media.Brushes.Black; Polyline PL = new Polyline();//绘制折线 PointCollection collection = new PointCollection(); collection.Add(new System.Windows.Point(p0.X, p0.Y)); collection.Add(new System.Windows.Point(p1.X, p1.Y)); collection.Add(new System.Windows.Point(p2.X, p2.Y)); collection.Add(new System.Windows.Point(p3.X, p3.Y)); PL.Points = collection; PL.Stroke = new SolidColorBrush(Colors.Red); PL.StrokeThickness = 1; GridImg.Children.Add(LX); GridImg.Children.Add(LY); GridImg.Children.Add(PL); }
作者:眾尋
出处:https://www.cnblogs.com/ZXdeveloper/p/3781688.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
分类:
WPF
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何统计不同电话号码的个数?—位图法
· C#高性能开发之类型系统:从 C# 7.0 到 C# 14 的类型系统演进全景
· 从零实现富文本编辑器#3-基于Delta的线性数据结构模型
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 长文讲解 MCP 和案例实战
· 用c#从头写一个AI agent,实现企业内部自然语言数据统计分析
· 三维装箱问题(3D Bin Packing Problem, 3D-BPP)
· Windows上,10分钟构建一个本地知识库
· Java虚拟机代码是如何一步一步变复杂且难以理解的?
· 凯亚物联网平台如何通过MQTT网络组件接入设备