zoukankan      html  css  js  c++  java
  • Silverlight WorkFlow画图Canvas画布的处理

    前面简单的介绍了 Activity控件以及ArrowLine控件

    Activity和ArrowLine这两个控件,最终得要一个地方展现出来,而这个地方就在--Canvas画布上

    在Canvas画布上可以添加好多Activity和ArrowLine控件

    但是怎么把这些Activity和ArrowLine控件关联起来呢

    今天就简单的写一下,个人水平有限

    如的什么可以改进的地方,还望各位告诉一下

    还是拿图说话吧

    Canvas画布的Activity控件在右边的控件里增加进来的

    而ArrowLine带箭头的线是左键按下时画出来的分三部

    第一:目前ArrowLine画线是左键按下的时候,把当前的鼠标的坐标(foot)记录下来 ,在new ArrowLine的时候,把坐标(foot)传给ArrowLine里去;这样线的尾部的坐标就算确定了,

    第二:然后拖动鼠标的时候,记录当前移动鼠标的坐标(cap),同时修改 ArrowLine箭头的坐标(cap);

    第三:鼠标松开的时候,一条带箭头的线就划完了;

    画完的线不想用了内能删除,不能移动(以后改进一下...)

    也与一Activity控件之间没有任何关系。

    现在开始说一下Canvas有哪些的三个事件MouseLeftButtonDown、MouseMove、MouseLeftButtonUp。

    第一个是MouseLeftButtonDown:

    左键的时候,流程如下:

    代码如下:

     1             e.Handled = true;
    2 isMove = true;
    3 Point p = e.GetPosition(print);
    4 if (_newLine != null && p == _newLine.StartPoint)
    5 {
    6 return;
    7 }
    8
    9 FrameworkElement element = sender as FrameworkElement;
    10 element.CaptureMouse();
    11 double top = p.Y;
    12 double left = p.X;
    13
    14 _newLine = new ArrowLine(p, p);
    15 _newLine.Name = string.Format("ArrowLine_{0}", ++Index);
    16 _newLine.LineGuid = Wrapper.GuidValue;
    17 CreateArrowLine(_newLine);

    第二个MouseMove:

    鼠标在Canvas上移动的时流程图大致如下:

    代码如下:

     1             if (isMove)
    2 {
    3 Point p = e.GetPosition(print);
    4 if (p == _newLine.StartPoint)
    5 {
    6 RemoveArrowLine(_newLine);
    7 }
    8 else
    9 {
    10 _newLine.EndPoint = p;
    11 }
    12 }

    第三个MouseLeftButtonUp:

    鼠标弹起来的时流程图大致如下:

    代码如下:

     1             isMove = false;
    2 Is_Activity = false;
    3 e.Handled = false;
    4 FrameworkElement element = sender as FrameworkElement;
    5 element.ReleaseMouseCapture();
    6 if (_newLine == null)
    7 {
    8 return;
    9 }
    10 Point p = e.GetPosition(print);
    11 if (p == _newLine.StartPoint)
    12 {
    13 RemoveArrowLine(_newLine);
    14 }
    15 else
    16 {
    17 //-->如果当前的箭头,所连接的控件,与移动进去的控件不是同一控件的话。
    18 foreach (var v in DictControls)
    19 {
    20 IActivity iact = v.Value as IActivity;
    21 if (null == iact)
    22 {
    23 continue;
    24 }
    25 //-->获取当前控件的
    26 double top = Canvas.GetTop(v.Value);
    27 double left = Canvas.GetLeft(v.Value);
    28 //-->判断当前的箭头进入Activity控件区域
    29 if ((p.X >= left && p.X <= (left + v.Value.Width)) && (p.Y >= top && p.Y <= (top + v.Value.Height)))
    30 {
    31 //-->判断当前的箭头是否可以连接到Activity控件上去。
    32 if (!iact.IsConnection())
    33 {
    34 MessageBox.Show("不能连接");
    35 RemoveArrowLine(_newLine);
    36 continue;
    37 }
    38 //-->当前线的尾部控件与当前进入的控件相同,不进行操作
    39 if (null != _newLine.ArrowFootControl && _newLine.ArrowFootControl.Equals(v.Value))
    40 {
    41 continue;
    42 }
    43 IActivity arrowFoot = _newLine.ArrowFootControl as IActivity;
    44 if (arrowFoot != null && arrowFoot.CheckedArrowIsExists(iact))
    45 {
    46 MessageBox.Show("已经存在相同的线了");
    47 RemoveArrowLine(_newLine);
    48 continue;
    49 }
    50 string _point = string.Format("X_{0}_Y_{1}", _newLine.StartPoint.X, _newLine.StartPoint.Y);
    51 if (!iact.DictArrowFootPoint.ContainsKey(_newLine))
    52 {
    53 iact.DictArrowCapPoint.Add(_newLine, _newLine);
    54 _newLine.ArrowCapControl = v.Value;
    55 }
    56 break;
    57 }
    58 }
    59 }
    60 _newLine = null;

    Canvas当的三个事件处理基本说完了。

  • 相关阅读:
    第十四周学习报告
    20135206、20135236第四次试验报告
    20135206、20135236第三次试验报告
    第十三周学习报告
    20135206、20135236第二次实验报告
    第十一周学习报告
    20135206于佳心【家庭作业汇总】
    20135236、20135206第一次试验报告
    luogu题解 CF767C 【Garland】
    第七届Code+程序设计全国挑战赛 normal T1 最小路径串
  • 原文地址:https://www.cnblogs.com/xiaotuni/p/2368195.html
Copyright © 2011-2022 走看看