欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > C# 流程图demo

C# 流程图demo

2024/10/24 8:19:34 来源:https://blog.csdn.net/xuelin663/article/details/139339165  浏览:    关键词:C# 流程图demo

1、向panel添加控件。

2、panel控件中的控件可以自由拖动。

3、控件之间连线。

4、连线的控件,拖动时更新连线。

 流程图连接线

//流程图连接线private void draggablePanel1_Paint(){Graphics g = this.draggablePanel1.CreateGraphics();g.Clear(this.BackColor);Pen pen = new Pen(Color.Black, 2);foreach (var lineitem in line){// 流程图连接线g.DrawLine(pen, lineitem.Start.X, lineitem.Start.Y, lineitem.End.X, lineitem.End.Y);// 箭头int arrowSize = 6;Point[] arrowPoints = { new Point(lineitem.End.X, lineitem.End.Y), new Point(lineitem.End.X - arrowSize, lineitem.End.Y - arrowSize), new Point(lineitem.End.X - arrowSize, lineitem.End.Y + arrowSize) };g.FillPolygon(Brushes.Black, arrowPoints);}Invalidate();}

 添加画线坐标到集合

 //添加画线坐标到集合private void Addline(){int StartX = 0;int StartY = 0;int EndX = 0;int EndY = 0;if (!string.IsNullOrEmpty(downlinef) && !string.IsNullOrEmpty(downlines)){foreach (Control ctr in draggablePanel1.Controls){if (ctr.Name == downlinef){int w = ctr.Width / 2;int h = ctr.Height / 2;StartX = ctr.Location.X + w;StartY = ctr.Location.Y + h;}if (ctr.Name == downlines){int w = ctr.Width / 2;int h = ctr.Height / 2;EndX = ctr.Location.X + w;EndY = ctr.Location.Y - 6;}}line.Add(new ctrline(new Point(StartX, StartY), new Point(EndX, EndY), downlinef, downlines));}}

移动控件时更新画线坐标

 private void updateline(string ctrname,Point currlocation){if (line.Count > 0){for (int i = 0; i < line.Count; i++){if (line[i].Ctrname == ctrname){line[i].Start=currlocation;txtmsg.Text += "开始" + ctrname + " X:" + currlocation.X + ",Y:" + currlocation.Y + "\r\n";}if (line[i].EndCtrname == ctrname){line[i].End = currlocation;txtmsg.Text += "结束" + ctrname + " X:" + currlocation.X + ",Y:" + currlocation.Y + "\r\n";}}}}

暂时先这样,后续再优化……

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com