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

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

相关推荐
艾莉丝努力练剑35 分钟前
【C++:异常】C++ 异常处理完全指南:从理论到实践,深入理解栈展开与最佳实践
java·开发语言·c++·安全·c++11
岁忧7 小时前
GoLang五种字符串拼接方式详解
开发语言·爬虫·golang
tyatyatya7 小时前
MATLAB基础数据类型教程:数值型/字符型/逻辑型/结构体/元胞数组全解析
开发语言·matlab
心无旁骛~8 小时前
python多进程和多线程问题
开发语言·python
星云数灵8 小时前
使用Anaconda管理Python环境:安装与验证Pandas、NumPy、Matplotlib
开发语言·python·数据分析·pandas·教程·环境配置·anaconda
kaikaile19958 小时前
基于遗传算法的车辆路径问题(VRP)解决方案MATLAB实现
开发语言·人工智能·matlab
四问四不知8 小时前
Rust语言进阶(结构体)
开发语言·后端·rust
q***9948 小时前
index.php 和 php
开发语言·php
oioihoii8 小时前
C++网络编程:从Socket混乱到优雅Reactor的蜕变之路
开发语言·网络·c++
笙年9 小时前
JavaScript Promise,包括构造函数、对象方法和类方法
开发语言·javascript·ecmascript