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

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

相关推荐
斐波娜娜18 分钟前
Maven详解
java·开发语言·maven
小码氓41 分钟前
Java填充Word模板
java·开发语言·spring·word
暮鹤筠1 小时前
[C语言初阶]操作符
c语言·开发语言
Boilermaker19923 小时前
【Java EE】Mybatis-Plus
java·开发语言·java-ee
aramae3 小时前
C++ -- STL -- vector
开发语言·c++·笔记·后端·visual studio
Tony小周3 小时前
实现一个点击输入框可以弹出的数字软键盘控件 qt 5.12
开发语言·数据库·qt
lixzest3 小时前
C++ Lambda 表达式详解
服务器·开发语言·c++·算法
沉默媛4 小时前
如何安装python以及jupyter notebook
开发语言·python·jupyter
_Chipen4 小时前
C++基础问题
开发语言·c++
止观止5 小时前
JavaScript对象创建9大核心技术解析
开发语言·javascript·ecmascript