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";
                    }
                }
            }
        }

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

相关推荐
yeziyfx10 分钟前
kotlin中集合的用法
android·开发语言·kotlin
lph197227 分钟前
快速分页wpf
c#
三体世界1 小时前
TCP传输控制层协议深入理解
linux·服务器·开发语言·网络·c++·网络协议·tcp/ip
随心点儿1 小时前
使用python 将多个docx文件合并为一个word
开发语言·python·多个word合并为一个
不学无术の码农1 小时前
《Effective Python》第十三章 测试与调试——使用 Mock 测试具有复杂依赖的代码
开发语言·python
tomcsdn311 小时前
SMTPman,smtp的端口号是多少全面解析配置
服务器·开发语言·php·smtp·邮件营销·域名邮箱·邮件服务器
试行1 小时前
C#System.Runtime.InteropServices.ExternalException (0x80004005): GDI+ 中发生一般性错误。
c#
EnigmaCoder2 小时前
Java多线程:核心技术与实战指南
java·开发语言
大白的编程日记.3 小时前
【计算机基础理论知识】C++篇(二)
开发语言·c++·学习
网小鱼的学习笔记3 小时前
python中MongoDB操作实践:查询文档、批量插入文档、更新文档、删除文档
开发语言·python·mongodb