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

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

相关推荐
IT=>小脑虎19 分钟前
C++零基础衔接进阶知识点【详解版】
开发语言·c++·学习
nbsaas-boot35 分钟前
Go vs Java 的三阶段切换路线图
java·开发语言·golang
码农小韩1 小时前
基于Linux的C++学习——指针
linux·开发语言·c++·学习·算法
微露清风1 小时前
系统性学习C++-第十九讲-unordered_map 和 unordered_set 的使用
开发语言·c++·学习
BBBBBAAAAAi1 小时前
Claude Code安装记录
开发语言·前端·javascript
毕设源码-钟学长1 小时前
【开题答辩全过程】以 基于Java的慕课点评网站为例,包含答辩的问题和答案
java·开发语言
maozexijr1 小时前
Rabbit MQ中@Exchange(durable = “true“) 和 @Queue(durable = “true“) 有什么区别
开发语言·后端·ruby
深圳佛手1 小时前
使用java,怎么样高效地读取一个大文件(10g以上)?
java·开发语言
xiaolyuh1231 小时前
【XXL-JOB】 GLUE模式 底层实现原理
java·开发语言·前端·python·xxl-job
源码获取_wx:Fegn08951 小时前
基于 vue智慧养老院系统
开发语言·前端·javascript·vue.js·spring boot·后端·课程设计