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

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

相关推荐
lsswear11 分钟前
php fiber 应用
开发语言·php
(・Д・)ノ17 分钟前
python打卡day28
开发语言·python
保利九里21 分钟前
java中的方法详解
java·开发语言·python
灏瀚星空32 分钟前
Python标准库完全指南:os、sys与math模块详解与实战应用
开发语言·python·microsoft
坐吃山猪35 分钟前
Python-Flask-Dive
开发语言·python·flask
Chandler2443 分钟前
Go语言 GORM框架 使用指南
开发语言·后端·golang·orm
zimoyin1 小时前
Java 快速转 C# 教程
java·开发语言·c#
向宇it1 小时前
【unity游戏开发——编辑器扩展】使用MenuItem自定义菜单栏拓展
开发语言·ui·unity·c#·编辑器·游戏引擎
oneDay++1 小时前
# IntelliJ IDEA企业版安装与配置全指南:避坑详解
java·开发语言·经验分享·学习·学习方法
动感光博1 小时前
Unity碰撞检测(射线投射、胶囊体投射)、交互(图层、掩码)
unity·c#·游戏引擎·游戏程序·动画