资源简介
【实例截图】
【核心代码】
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace GDIDrawFlow
{
/// <summary>
/// DrawLine 的摘要说明。
/// </summary>
public class DrawObject
{
#region 变量定义
private DrawFlowControl control;//主程序
public ArrayList arrLineList;//线的数组
private ArrayList arrNodeList;//节点的数组
private ArrayList arrLineConnectNode;//连接到活动节点的线
private ArrayList arrDrawStringList;//写字板的数组
private Line lineThisLine;//当前正在编辑的线(用于对线的创建)
private Node nodeThisNode;//当前正在编辑的节点(用于对节点的创建)
private int iLineFirstNodeX,iLineFirstNodeY,iLineSecondNodeX,iLineSecondNodeY,iLine3thNodeX,iLine3thNodeY,iLine4thNodeX,iLine4thNodeY;//正在编辑的线的坐标信息
private Line lineTempLine;//临时表示的线。(鼠标在其变化点的线)
private Line lineSelectLine;//选中的线(对于线的修改)
private int iTempNodeIndex;//临时表示的线的某一端
private int iSelectNodeIndex;//选中的线的某一端
private int iTempNodeX=0,iTempNodeY=0;//画节点的时候的节点起点坐标
private bool bDrawLine=false;//是否开始重画线(paint事件)
private int iMouseInitX,iMouseInitY;//鼠标移动的初始坐标(每次移动刷新)
private int iNodeX,iNodeY,iNodeWidth,iNodeHeight;//当前绘制的节点信息
private bool bDrawNode=false;//是否画节点
private Node nodeSelectNode;//选中的节点
private bool bDrawConnectNodeLine=false;//是否重画连接到活动节点上面的线(移动节点)
private Color bckColor;//背景色
private Bitmap bitmapMemeory,bitmapBackGroupMap;//画板 ,背景图
private Graphics graDrawPanel;//画板
private Graphics graDrawLine;//无意义
private Pen penDrawLine;//画线笔
private Pen penDrawNode;//画节点笔
private Pen penDrawPoint;//画点笔
private Pen penDrawString;//写字笔
private Pen penDrawBeeLine;//画直线笔
private SelectPoint selectPoint;//选择(活动)表示点
private int iMouseDownX,iMouseDownY;//记录鼠标的按下坐标(用于 移动连接到节点的线的移动距离判断)
public Object lastEdit;//记录上次编辑的元素
private int iAutoConnectLinePointIndex=9;//应画为红色的线的活动表示标识
private Node nodeTempNode=null;//节点的临时选定
private int iResizeNodeMouseIndex=99;//编辑节点大小的 编辑方式 如:横向或纵向改变
private int iResizeDSMouseIndex=99;//编辑写字板大小的 编辑方式 如:横向或纵向改变
//private bool bResizeNode=false;//是否要改变节点的大小
private DrawString drawStringThisDS;//当前要画写字板
private DrawString drawStringSelectDS;//选定的写字板
private DrawString drawStringTempDS;//用于改变写字板的大小
private int iDrawStringX,iDrawStringY,iDrawStringWidth,iDrawStringHeight;//当前的写字板的坐标和长,宽
private bool bDrawString;//是否画写字板
private int iTempDSX=0,iTempDSY=0;//做写字板的时候鼠标第一次按下的坐标
private Font fontDrawString;//写字板的字体信息
private TextBox TBDrawStringContent;//写字板的内容编辑
private TextBox TBnodeContent;//节点的名称编辑
private TextBox TBLineContent;//线的名称编辑
private string strDSContent;//当前写字板的内容
private RectangleF re;//写字板写字区域
//private bool bResizeDS;//是否改变写字板的大小
private GDIDrawFlow.Node.DrawObjectType currentObjectType; //定义当前节点的类型
public Bitmap bgImage;//背景图片
private Line newLine;//要画的线
private Node newNode;//要画的节点
private DrawString newDrawString;//要画的写字板
private Object objPrepareDel;//要删除的元素
private bool bSelectAll=false;//是否选择了全部的元素
private bool bSelectAllReday=false;//是否已经选择了全部的元素
private ArrayList arrLineSelectList;//线的数组
private ArrayList arrNodeSelectList;//节点的数组
private ArrayList arrLineNotSelectList;//没有被选择的线的数组
private ArrayList arrNodeNotSelectList;//没有被选择的节点的数组
private ArrayList arrDrawStringSelectList;//写字板的数组
private ArrayList arrDrawStringNotSelectList;//没有被选择的写字板的数组
private bool bNotSelectAnyOne=false;//鼠标按下的时候没有选择中任何一个节点
private int iMouseSelectX,iMouseSelectY;//区域选择的坐标
private int iMouseSelectWidth,iMouseSelectHeight;//区域选择的长度和宽度
private bool bDrawSelectRectangle=false;//画出选择虚线框
private bool bDrawSelectElement=false;//是否画出选择定的元素
private bool bSelectRectangleReday=false;//是否已经选择了区域的元素
private bool bIsAtSelect=false;//是否正在选定区域选择的区域。。(在画区域选择线)
private Size size;//屏幕尺寸
public bool bStartFlag=false;//是否已经画了开始节点
public bool bEndFlag=false;//是否已经画了结束节点
private ArrayData arrayData;//序列化数组
private GetTypeImage getTypeImage;//获取节点图片
private Image image;// 要绘制的图片 节点上的使用
private int iOnLineSegment=9;//鼠标在折线段上的标识
private GetTypeCursor getTypeCursor;//自定义鼠标图形
public Point location=new Point(100,100);
private bool b_IsDownMouseRight=false;//是否按下鼠标右键
public int i_GeneralCount=0;//普通节点的数字。
public object obj_SeriesDrawEle;//连续绘制图元
public int[] iArr_ShowHelpTip;//存储节点的连接信息(只一次)
public Node node_OperationTemp;//临时编辑的节点
public Line line_OperationTemp;//临时编辑的线
public DrawString ds_OperationTemp;//临时编辑的写字板
public bool b_PressDirctKey;//是否按下方向键
DrawFlowTable dft;
public bool isAlpha=true; //图元是否支持半透明
#endregion
#region 构造方法
public DrawObject(DrawFlowControl control)
{
this.control=control;
init();
}
#endregion
#region 初始化
private void init()
{//获取父框架
this.SerializeInit();
this.arrLineList=this.arrayData.arrLineList;
this.arrNodeList=this.arrayData.arrNodeList;
this.arrLineConnectNode=this.arrayData.arrLineConnectNode;
this.arrDrawStringList=this.arrayData.arrDrawStringList;
this.arrLineSelectList=this.arrayData.arrLineSelectList;
this.arrNodeSelectList=this.arrayData.arrNodeSelectList;
this.arrDrawStringSelectList=this.arrayData.arrDrawStringSelectList;
this.arrLineNotSelectList=this.arrayData.arrLineNotSelectList;
this.arrNodeNotSelectList=this.arrayData.arrNodeNotSelectList;
this.arrDrawStringNotSelectList=this.arrayData.arrDrawStringNotSelectList;
this.bitmapBackGroupMap=this.control.bitmapBackGroupMap;
this.bitmapMemeory=this.control.bitmapMemeory;
this.graDrawLine=this.control.graDrawLine;
this.graDrawPanel=this.control.graDrawPanel;
this.penDrawLine=this.control.penDrawLine;
this.penDrawNode=this.control.penDrawNode;
this.penDrawPoint=this.control.penDrawPoint;
this.penDrawString=this.control.penDrawString;
this.penDrawBeeLine=this.control.penDrawBeeLine;
this.bckColor = this.control.BackColor;
this.fontDrawString=this.control.fontDrawString;
this.TBDrawStringContent=this.control.drawStringContent;
this.TBnodeContent=this.control.TBnodeContent;
this.TBLineContent=this.control.TBLineContent;
this.bgImage=this.control.bgImage;
this.size=this.control.Size;
this.getTypeCursor=new GetTypeCursor();
this.iArr_ShowHelpTip=new int[20];
// this.iLineFirstNodeX=150;
// this.iLineFirstNodeY=100;
this.iLineSecondNodeX=200;
this.iLineSecondNodeY=100;
this.iLine3thNodeX=200;
this.iLine3thNodeY=200;
this.iLine4thNodeX=250;
this.iLine4thNodeY=200;
this.iNodeWidth=50;
this.iNodeHeight=55;
this.iDrawStringWidth=50;
this.iDrawStringHeight=55;
this.AttriShow();
dft=new DrawFlowTable (this);
DrawBackGround();
this.RefreshBackground();
}
private void SerializeInit()
{
this.arrayData=new ArrayData();
// Stream stream = File.Open("/arrayData.xml", FileMode.Create);
// BinaryFormatter formatter = new BinaryFormatter();
// formatter.Serialize(stream, this.arrayData);
// stream.Close();
// this.arrayData=null;
// stream = File.Open("/arrayData.xml", FileMode.Open);
// formatter = new BinaryFormatter();
// this.arrayData=((ArrayData)formatter.Deserialize(stream));
// stream.Close();
/****************************
MessageForm.Show("123");
byte[] byt=new byte[1024];
MemoryStream stream=new MemoryStream (byt);
BinaryFormatter formatter = new BinaryFormatter();
MessageForm.Show("123456");
formatter.Serialize(stream,this.arrayData);
MessageForm.Show("123789");
this.arrayData=null;
//stream = File.Open("arrayData.xml", FileMode.Open);
formatter = new BinaryFormatter();
MemoryStream ms=new MemoryStream (byt);
MessageForm.Show(byt.Length.ToString());
this.arrayData=((ArrayData)formatter.Deserialize(ms));
MessageForm.Show("abxcsdjfhasdkjfh");
***************************/
this.selectPoint=new SelectPoint();
// stream = File.Open("/selectPoint.xml", FileMode.Create);
// formatter = new BinaryFormatter();
// formatter.Serialize(stream, this.selectPoint);
// stream.Close();
// this.selectPoint=null;
// stream = File.Open("/selectPoint.xml", FileMode.Open);
// formatter = new BinaryFormatter();
// this.selectPoint=((SelectPoint)formatter.Deserialize(stream));
// stream.Close();
//
this.getTypeImage=new GetTypeImage();
// stream = File.Open("/getTypeImage.xml", FileMode.Create);
// formatter = new BinaryFormatter();
// formatter.Serialize(stream, this.getTypeImage);
// stream.Close();
// this.getTypeImage=null;
// stream = File.Open("/getTypeImage.xml", FileMode.Open);
// formatter = new BinaryFormatter();
// this.getTypeImage=((GetTypeImage)formatter.Deserialize(stream));
// stream.Close();
}
#endregion
#region 对象创建
public void NewLine(Line.DrawObjectType type)
{
if(this.lineThisLine!=null)
{
if(this.lineThisLine.ObjectType==type)
{
return;
}
}
if(!this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
this.newLine=new Line(type,arrLineList.Count);
this.lineThisLine=this.newLine;
if(type==Line.DrawObjectType.DrawBeeLine)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.BeeLine);
}
else
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.FoldLine);
}
this.nodeThisNode=null;
this.drawStringThisDS=null;
if(this.obj_SeriesDrawEle!=null)
{
this.obj_SeriesDrawEle=this.lineThisLine;
}
}
}
public void NewDefaultLine(Line.DrawObjectType type,Point location)
{
if(!this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
this.newLine=new Line(type,arrLineList.Count);
if(type==Line.DrawObjectType.DrawBeeLine)
{
this.newLine.X0=location.X;
this.newLine.Y0=location.Y;
this.newLine.X1=location.X 150;
this.newLine.Y1=location.Y 100;
this.newLine.LineNodeCount=4;
this.lastEdit=this.newLine;
this.selectPoint.SetLinePoint(this.newLine.X0,this.newLine.Y0,this.newLine.X1,this.newLine.Y1);
}
else if(type==Line.DrawObjectType.DrawFoldLine)
{
this.newLine.X0=location.X;
this.newLine.Y0=location.Y;
this.newLine.X1=location.X 150;
this.newLine.Y1=location.Y;
this.newLine.X2=location.X 150;
this.newLine.Y2=location.Y 100;
this.newLine.X3=location.X 300;
this.newLine.Y3=location.Y 100;;
this.newLine.LineNodeCount=8;
this.lastEdit=this.newLine;
this.selectPoint.SetFlodLinePoint(this.newLine);
}
this.arrLineList.Add(this.newLine);
this.reDrawBitmap(this.graDrawPanel,10,10);
this.RefreshBackground();
this.lineThisLine=null;
this.control.Cursor=Cursors.Default;
// this.control.Invalidate();
}
}
public void NewNode(Node.DrawObjectType type)
{
if(this.nodeThisNode!=null)
{
if(this.nodeThisNode.ObjectType==type)
{
return;
}
}
if(!this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
this.newNode=new Node(this.arrNodeList.Count,type,getDefaultText(type));
this.nodeThisNode=this.newNode;
this.SetNodeCursor(type);
this.lineThisLine=null;
this.drawStringThisDS=null;
this.currentObjectType=type;
if(this.obj_SeriesDrawEle!=null)
{
this.obj_SeriesDrawEle=this.nodeThisNode;
}
}
}
public void NewDefaultNode(Node.DrawObjectType type,Point location)
{
if(type==Node.DrawObjectType.DrawNodeBegin && this.bStartFlag)
{
MessageForm.Show("对不起,开始节点创建受限制。","DrawFlow");
return;
}
if(type==Node.DrawObjectType.DrawNodeEnd && this.bEndFlag)
{
MessageForm.Show("对不起,结束节点创建受限制。","DrawFlow");
return;
}
if(!this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
if(this.i_GeneralCount>=20 && type==Node.DrawObjectType.DrawNodeGeneral)
{
MessageForm.Show("对不起,您目前选择的节点限制为20个.","DrawFlow");
return;
}
this.newNode=new Node(this.arrNodeList.Count,type,getDefaultText(type));
this.newNode.X=location.X;
this.newNode.Y=location.Y;
this.newNode.Width=50;
this.newNode.Height=55;
this.lastEdit=this.newNode;
this.selectPoint.SetRectanglePoint(this.newNode.X,this.newNode.Y,this.newNode.Width,this.newNode.Height);
this.arrNodeList.Add(this.newNode);
this.currentObjectType=type;
this.reDrawBitmap(this.graDrawPanel,10,10);
this.RefreshBackground();
this.nodeThisNode=null;
this.control.Cursor=Cursors.Default;
if(type==Node.DrawObjectType.DrawNodeBegin)
{
this.bStartFlag=true;
}
else if(type==Node.DrawObjectType.DrawNodeEnd)
{
this.bEndFlag=true;
}
else if(type==Node.DrawObjectType.DrawNodeGeneral)
{
this.i_GeneralCount ;
}
// this.control.Invalidate();
}
// else
// {
// if(this.drawStringThisDS!=null || this.nodeThisNode!=null || this.lineThisLine!=null)
// {
// MessageForm.Show("对不起,您已经选择了自定义画图。","DrawFlow");
// }
// }
}
public void NewDrawString()
{
if(this.drawStringThisDS==null && !this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
this.newDrawString=new DrawString(this.arrDrawStringList.Count);
this.drawStringThisDS=this.newDrawString;
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.String);
this.strDSContent=this.drawStringThisDS.Content;
this.lineThisLine=null;
this.nodeThisNode=null;
if(this.obj_SeriesDrawEle!=null)
{
this.obj_SeriesDrawEle=this.drawStringThisDS;
}
}
}
public void NewDefaultDrawString(Point location)
{
if(!this.bIsAtSelect)
{
this.bSelectRectangleReday=false;
this.newDrawString=new DrawString(this.arrDrawStringList.Count);
this.newDrawString.X=location.X;
this.newDrawString.Y=location.Y;
this.newDrawString.Width=80;
this.newDrawString.Height=60;
this.strDSContent=this.newDrawString.Content;
this.lastEdit=this.newDrawString;
this.selectPoint.SetRectanglePoint(this.newDrawString.X,this.newDrawString.Y,this.newDrawString.Width,this.newDrawString.Height);
this.arrDrawStringList.Add(this.newDrawString);
this.reDrawBitmap(this.graDrawPanel,10,10);
this.RefreshBackground();
this.drawStringThisDS=null;
this.control.Cursor=Cursors.Default;
// this.control.Invalidate();
}
// else
// {
// if(this.drawStringThisDS!=null || this.nodeThisNode!=null || this.lineThisLine!=null)
// {
// MessageForm.Show("对不起,您已经选择了自定义画图。","DrawFlow");
// }
// }
}
public void SetNodeCursor(Node.DrawObjectType type)
{
if(type==Node.DrawObjectType.DrawNodeBegin)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.NodeBegin);
}
else if(type==Node.DrawObjectType.DrawNodeGeneral)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.NodeGeneral);
}
else if(type==Node.DrawObjectType.DrawSpecificallyOperation)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.SpecificallyOperation);
}
else if(type==Node.DrawObjectType.DrawGradation)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Gradation);
}
else if(type==Node.DrawObjectType.DrawSynchronization)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Synchronization);
}
else if(type==Node.DrawObjectType.DrawAsunder)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Asunder);
}
else if(type==Node.DrawObjectType.DrawConverge)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Converge);
}
else if(type==Node.DrawObjectType.DrawGather)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Gather);
}
else if(type==Node.DrawObjectType.DrawJudgement)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Judgement);
}
else if(type==Node.DrawObjectType.DrawDataNode)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.DataNode);
}
else if(type==Node.DrawObjectType.DrawNodeEnd)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.NodeEnd);
}
else if(type==Node.DrawObjectType.DrawRectangle)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Rectangle);
}
else if(type==Node.DrawObjectType.DrawEllipse)
{
this.control.Cursor=this.getTypeCursor.GetCursor(GetTypeCursor.DrawType.Eillpse);
}
}
#endregion
#region 绘制界面
public static string getDefaultText(Node.DrawObjectType type)
{
switch(type)
{
case Node.DrawObjectType.DrawNodeBegin:
return "开始";
case Node.DrawObjectType.DrawNodeGeneral:
return "任务";
case Node.DrawObjectType.DrawSpecificallyOperation:
return "特定操作";
case Node.DrawObjectType.DrawGradation:
return "顺序";
case Node.DrawObjectType.DrawSynchronization:
return "同步";
case Node.DrawObjectType.DrawAsunder:
return "分支";
case Node.DrawObjectType.DrawConverge:
return "汇聚";
case Node.DrawObjectType.DrawGather:
return "汇总连接";
case Node.DrawObjectType.DrawJudgement:
return "判断";
case Node.DrawObjectType.DrawDataNode:
return "应用数据";
case Node.DrawObjectType.DrawNodeEnd:
return "结束";
case Node.DrawObjectType.DrawRectangle:
return "矩形";
case Node.DrawObjectType.DrawEllipse:
return "椭圆形";
}
return "";
}
public string GetLineDefaultText(Line.DrawObjectType type)
{
switch(type)
{
case Line.DrawObjectType.DrawBeeLine:
return "直线";
case Line.DrawObjectType.DrawFoldLine:
return "折线";
}
return "";
}
/// <summary>
/// 绘制背景网格
/// </summary>
private void DrawBackGround()
{
int width=this.bgImage.Width;
int height=this.bgImage.Height;
for(int i=0;i<this.control.Width;i =width)
{
for(int j=0 ;j<this.control.Height;j =height)
{
graDrawPanel.DrawImage(this.bgImage,i,j,width,height);
}
}
}
/// <summary>
/// 重画背景元素(没有被激活的元素)
/// </summary>
/// <param name="g">画板</param>
/// <param name="drawCode">元素代码表示drawCode=0表示节点,drawCode=1 表示直线,drawCode=1 表示写字板</param>
/// <param name="index">被激活元素的数组下标</param>
public void reDrawBitmap(Graphics g,int drawCode,int index)//drawCode=0表示节点,drawCode=1 表示直线,drawCode=1 表示写字板
{
DrawBackGround();
Line line;
Node node;
DrawString drawString;
for(int i=0;i<this.arrLineList.Count;i )
{
if(drawCode!=1 || i!=index)//是否绘制该线
{
line=((Line)arrLineList[i]);
this.penDrawLine.Color=line.LineColor;
this.penDrawLine.Width=line.LineSize;
if(line.ObjectType==Line.DrawObjectType.DrawBeeLine)
{
g.DrawLine(this.penDrawLine,line.X0,line.Y0,line.X1,line.Y1);
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X0 line.X1)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y0 line.Y1)/2);
}
else
{
this.penDrawBeeLine.Color=line.LineColor;
this.penDrawBeeLine.Width=line.LineSize;
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(0),line.GetLineNodeInfo(1),line.GetLineNodeInfo(2),line.GetLineNodeInfo(3));
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(2),line.GetLineNodeInfo(3),line.GetLineNodeInfo(4),line.GetLineNodeInfo(5));
g.DrawLine(this.penDrawLine,line.GetLineNodeInfo(4),line.GetLineNodeInfo(5),line.GetLineNodeInfo(6),line.GetLineNodeInfo(7));
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X1 line.X2)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y1 line.Y2)/2);
}
}
}
for(int i=0;i<this.arrNodeList.Count;i )
{
if(drawCode!=0 || i!=index)//是否绘制该节点
{
node=((Node)arrNodeList[i]);
this.image=this.getTypeImage.GetImage(node.ObjectType);
if(this.image!=null)
{
DrawImage(g,this.image,node.X,node.Y,node.Width,node.Height);
}
else
{
if(node.ObjectType==Node.DrawObjectType.DrawRectangle)
{
this.penDrawNode.Color=node.BorderColor;
g.DrawRectangle(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillRectangle(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
else
{
this.penDrawNode.Color=node.BorderColor;
g.DrawEllipse(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillEllipse(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
}
//g.DrawString(node.NodeText,new Font("宋体",10),new SolidBrush(Color.Black),node.X,node.Y);
this.control.testDrawLength.Font=node.NodeTextFont;
this.control.testDrawLength.Text=node.NodeText;
int stringleft=node.X node.Width/2-this.control.testDrawLength.Width/2 3;
g.DrawString(node.NodeText,node.NodeTextFont,new SolidBrush(node.NodeTextColor),stringleft,node.Y node.Height);
}
}
for(int i=0;i<this.arrDrawStringList.Count;i )
{
if(drawCode!=2 || i!=index)//是否绘制该写字板
{
drawString =((DrawString)this.arrDrawStringList[i]);
int width,height;
if(drawString.Width<=2)
{
width=2;
}
else
{
width=drawString.Width;
}
if(drawString.Height<=2)
{
height=2;
}
else
{
height=drawString.Height;
}
this.re=new RectangleF(drawString.X,drawString.Y,width,height);
this.penDrawString.Color=drawString.DSTextColor;
g.DrawString(drawString.Content,drawString.DSTextFont,this.penDrawString.Brush,this.re);
}
}
}
/// <summary>
/// 绘制没有被选中的元素 (未被激活做为背景)
/// </summary>
/// <param name="g">画板</param>
public void ReDrawNotSelect(Graphics g)
{
DrawBackGround();
Line line;
Node node;
DrawString drawString;
for(int i=0;i<this.arrLineNotSelectList.Count;i )
{
line=(Line)this.arrLineNotSelectList[i];
this.penDrawLine.Color=line.LineColor;
this.penDrawLine.Width=line.LineSize;
if(line.ObjectType==Line.DrawObjectType.DrawBeeLine)
{
for(int j=0;j<line.LineNodeCount-2;j =2)
{
g.DrawLine(this.penDrawLine,line.GetLineNodeInfo(j),line.GetLineNodeInfo(j 1),line.GetLineNodeInfo(j 2),line.GetLineNodeInfo(j 3));
}
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X0 line.X1)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y0 line.Y1)/2);
}
else
{
this.penDrawBeeLine.Color=line.LineColor;
this.penDrawBeeLine.Width=line.LineSize;
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(0),line.GetLineNodeInfo(1),line.GetLineNodeInfo(2),line.GetLineNodeInfo(3));
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(2),line.GetLineNodeInfo(3),line.GetLineNodeInfo(4),line.GetLineNodeInfo(5));
g.DrawLine(this.penDrawLine,line.GetLineNodeInfo(4),line.GetLineNodeInfo(5),line.GetLineNodeInfo(6),line.GetLineNodeInfo(7));
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X1 line.X2)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y1 line.Y2)/2);
}
}
for(int i=0;i<this.arrNodeNotSelectList.Count;i )
{
node=((Node)arrNodeNotSelectList[i]);
this.image=this.getTypeImage.GetImage(node.ObjectType);
if(this.image!=null)
{
DrawImage(g,this.image,node.X,node.Y,node.Width,node.Height);
}
else
{
if(node.ObjectType==Node.DrawObjectType.DrawRectangle)
{
this.penDrawNode.Color=node.BorderColor;
g.DrawRectangle(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillRectangle(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
else
{
this.penDrawNode.Color=node.BorderColor;
g.DrawEllipse(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillEllipse(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
}
//g.DrawString(node.NodeText,new Font("宋体",10),new SolidBrush(Color.Black),node.X,node.Y);
this.control.testDrawLength.Font=node.NodeTextFont;
this.control.testDrawLength.Text=node.NodeText;
int stringleft=node.X node.Width/2-this.control.testDrawLength.Width/2 3;
g.DrawString(node.NodeText,node.NodeTextFont,new SolidBrush(node.NodeTextColor),stringleft,node.Y node.Height);
}
for(int i=0;i<this.arrDrawStringNotSelectList.Count;i )
{
drawString =((DrawString)this.arrDrawStringNotSelectList[i]);
int width,height;
if(drawString.Width<=2)
{
width=2;
}
else
{
width=drawString.Width;
}
if(drawString.Height<=2)
{
height=2;
}
else
{
height=drawString.Height;
}
this.re=new RectangleF(drawString.X,drawString.Y,width,height);
this.penDrawString.Color=drawString.DSTextColor;
g.DrawString(drawString.Content,drawString.DSTextFont,this.penDrawString.Brush,this.re);
}
}
public void ReDrawBitmapNodeMove(Graphics g,int index)//当有线连接到当前的节点上
{
DrawBackGround();
Line line;
Node node;
DrawString drawString;
for(int i=0;i<this.arrLineList.Count;i )
{
bool bConectNode=false;
for(int j=0;j<this.arrLineConnectNode.Count;j )
{
if(((Line)this.arrLineList[i]).Equals(((Line)this.arrLineConnectNode[j])))
{
bConectNode=true;
}
}
if(!bConectNode)
{
line=((Line)arrLineList[i]);
this.penDrawLine.Color=line.LineColor;
this.penDrawLine.Width=line.LineSize;
if(line.ObjectType==Line.DrawObjectType.DrawBeeLine)
{
for(int j=0;j<line.LineNodeCount-2;j =2)
{
g.DrawLine(this.penDrawLine,line.GetLineNodeInfo(j),line.GetLineNodeInfo(j 1),line.GetLineNodeInfo(j 2),line.GetLineNodeInfo(j 3));
}
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X0 line.X1)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y0 line.Y1)/2);
}
else
{
this.penDrawBeeLine.Color=line.LineColor;
this.penDrawBeeLine.Width=line.LineSize;
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(0),line.GetLineNodeInfo(1),line.GetLineNodeInfo(2),line.GetLineNodeInfo(3));
g.DrawLine(this.penDrawBeeLine,line.GetLineNodeInfo(2),line.GetLineNodeInfo(3),line.GetLineNodeInfo(4),line.GetLineNodeInfo(5));
g.DrawLine(this.penDrawLine,line.GetLineNodeInfo(4),line.GetLineNodeInfo(5),line.GetLineNodeInfo(6),line.GetLineNodeInfo(7));
this.control.testDrawLength.Text=line.Content;
int stringleft=(line.X1 line.X2)/2-this.control.testDrawLength.Width/2 3;
g.DrawString(line.Content,line.LineTextFont,new SolidBrush(line.LineColor),stringleft,(line.Y1 line.Y2)/2);
}
}
}
for(int i=0;i<this.arrNodeList.Count;i )
{
if( i!=index)
{
node=((Node)arrNodeList[i]);
this.image=this.getTypeImage.GetImage(node.ObjectType);
if(this.image!=null)
{
DrawImage(g,this.image,node.X,node.Y,node.Width,node.Height);
}
else
{
if(node.ObjectType==Node.DrawObjectType.DrawRectangle)
{
this.penDrawNode.Color=node.BorderColor;
g.DrawRectangle(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillRectangle(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
else
{
this.penDrawNode.Color=node.BorderColor;
g.DrawEllipse(this.penDrawNode,node.X,node.Y,node.Width,node.Height);
this.penDrawNode.Color=node.FillColor;
g.FillEllipse(this.penDrawNode.Brush,node.X,node.Y,node.Width,node.Height);
}
}
//g.DrawString(node.NodeText,new Font("宋体",10),new SolidBrush(Color.Black),node.X,node.Y);
this.control.testDrawLength.Font=node.NodeTextFont;
this.control.testDrawLength.Text=node.NodeText;
int stringleft=node.X node.Width/2-this.control.testDrawLength.Width/2 3;
g.DrawString(node.NodeText,node.NodeTextFont,new SolidBrush(node.NodeTextColor),stringleft,node.Y node.Height);
}
}
for(int i=0;i<this.arrDrawStringList.Count;i )
{
drawString =((DrawString)this.arrDrawStringList[i]);
int width,height;
if(drawString.Width<=2)
{
width=2;
}
else
{
width=drawString.Width;
}
if(drawString.Height<=2)
{
height=2;
}
else
{
height=drawString.Height;
}
this.re=new RectangleF(drawString.X,drawString.Y,width,height);
this.penDrawString.Color=drawString.DSTextColor;
g.DrawString(drawString.Content,drawString.DSTextFont,this.penDrawString.Brush,this.re);
}
}
public void RefreshBackground()
{
Size sz = this.control.Size;
if(sz.Width<=0) sz.Width=1;
if(sz.Height<=0) sz.Height=1;
Rectangle rt = new Rectangle(0, 0, sz.Width, sz.Height);
this.bitmapBackGroupMap = this.bitmapMemeory.Clone(rt, this.bitmapMemeory.PixelFormat);
this.control.BackgroundImage = this.bitmapBackGroupMap;
}
#endregion
#region 清除已经建立的连接
public void ClearLineConnectNode()
{
Line line;
for(int i=0;i<this.arrLineNotSelectList.Count;i )
{
line=(Line)this.arrLineNotSelectList[i];
if(this.isNodeInNodeList(line.FirstNode,this.arrNodeSelectList))
{
line.FirstNode.ConnectOutCount--;
line.FirstNode=null;
line.FirNodeInterfaceIndex=9;
}
if(this.isNodeInNodeList(line.SecondNode,this.arrNodeSelectList))
{
line.SecondNode.ConnectInCount--;
line.SecondNode=null;
line.SecNodeInterfaceIndex=9;
}
}
}
public void ClearNodeConnectLine()
{
Line line;
for(int i=0;i<this.arrLineSelectList.Count;i )
{
line=(Line)this.arrLineSelectList[i];
if(this.isNodeInNodeList(line.FirstNode,this.arrNodeNotSelectList))
{
line.FirstNode.ConnectOutCount--;
line.FirstNode=null;
line.FirNodeInterfaceIndex=9;
}
if(this.isNodeInNodeList(line.SecondNode,this.arrNodeNotSelectList))
{
line.SecondNode.ConnectInCount--;
line.SecondNode=null;
line.SecNodeInterfaceIndex=9;
}
}
}
public void ClearLineConnectAttrChange(Line line,int LinePointIndex)
{
if(LinePointIndex==0)
{
if(line.FirstNode!=null)
{
line.FirstNode.ConnectOutCount--;
line.FirstNode=null;
line.FirNodeInterfaceIndex=9;
}
}
else if(LinePointIndex==1)
{
if(line.SecondNode!=null)
{
line.SecondNode.ConnectInCount--;
line.SecondNode=null;
line.SecNodeInterfaceIndex=9;
}
}
}
#endregion
#region 判断鼠标所在的位置
public bool isNodeInNodeList(Node node,ArrayList arrayList)//是否节点在某节点数组中
{
for(int i=0;i<arrayList.Count;i )
{
Node node_=(Node)arrayList[i];
if(node==node_)
{
return true;
}
}
return false;
}
public Line IsMouseOnLine(int x,int y,ArrayList arrayList)
{
ArrayList arrLineList=arrayList;
Line line;
for(int i=0;i<arrLineList.Count;i )
{
line=((Line)arrLineList[i]);
if(line.ObjectType==Line.DrawObjectType.DrawBeeLine)
{
int x0=line.GetLineNodeInfo(0);
int y0=line.GetLineNodeInfo(1);
int x1=line.GetLineNodeInfo(2);
int y1=line.GetLineNodeInfo(3);
double douMLocToFir=this.GetDistance(new Point(x0,y0),new Point(x,y));
double douMLocToSec=this.GetDistance(new Point(x1,y1),new Point(x,y));
double douFirToSec=this.GetDistance(new Point(x0,y0),new Point(x1,y1));
if(0<(douMLocToFir douMLocToSec-douFirToSec) && (douMLocToFir douMLocToSec-douFirToSec)<1)
{
this.control.Cursor=Cursors.SizeAll;
return line;
}
else
{
this.control.Cursor=Cursors.Default;
}
}
else
{
for(int j=0;j<line.LineNodeCount-2;j =2)
{
int x0=line.GetLineNodeInfo(j);
int y0=line.GetLineNodeInfo(j 1);
int x1=line.GetLineNodeInfo(j 2);
int y1=line.GetLineNodeInfo(j 3);
double douMLocToFir=this.GetDistance(new Point(x0,y0),new Point(x,y));
double douMLocToSec=this.GetDistance(new Point(x1,y1),new Point(x,y));
double douFirToSec=this.GetDistance(new Point(x0,y0),new Point(x1,y1));
if(0<(douMLocToFir douMLocToSec-douFirToSec) && (douMLocToFir douMLocToSec-douFirToSec)<1)
{
this.control.Cursor=Cursors.SizeAll;
this.iOnLineSegment=j/2;
return line;
}
else
{
this.control.Cursor=Cursors.Default;
}
}
}
}
this.control.Cursor=Cursors.Default;
this.iOnLineSegment=9;
return null;
}
public double GetDistance(Point p1,Point p2)//判断两点间的距离
{
return Math.Sqrt(Math.Pow((p1.X - p2.X),2) Math.Pow((p1.Y - p2.Y ),2));
}
public Node IsMouseOnNode(int x,int y,ArrayList arrayList)//判断鼠标是否在节点上
{
ArrayList arrNodeList=arrayList;
for(int i=arrNodeList.Count;i>0;i--)//倒序 查询 最后画的节点 位于最上面
{
Node node=((Node)arrNodeList[i-1]);
if(node.X<x && x<node.X node.Width && node.Y<y && y<node.Y node.Height)
{
this.control.Cursor=Cursors.SizeAll;
return node;
}
else
{
this.control.Cursor=Cursors.Default;
}
}
this.control.Cursor=Cursors.Default;
return null;
}
public DrawString IsMouseOnDrawString(int x,int y,ArrayList arrayList)
{
ArrayList arrDrawStringList=arrayList;
for(int i=arrDrawStringList.Count;i>0;i--)//倒序查询 最后画的写字板位于最上面
{
DrawString drawString=((DrawString)arrDrawStringList[i-1]);
if(drawString.X<x && x<drawString.X drawString.Width && drawString.Y<y && y<drawString.Y drawString.Height)
{
this.control.Cursor=Cursors.SizeAll;
return drawString;
}
else
{
this.control.Cursor=Cursors.Default;
}
}
this.control.Cursor=Cursors.Default;
return null;
}
public bool IsMouseOnAnyControl(int x,int y)
{
Line line=null;
Node node=null;
DrawString drawString=null;
if(this.bSelectAllReday || this.bSelectRectangleReday)//全部选择的点击判断
{
line=this.IsMouseOnLine(x,y,this.arrLineList);
node=this.IsMouseOnNode(x,y,this.arrNodeList);
drawString=this.IsMouseOnDrawString(x,y,this.arrDrawStringList);
if(line==null && node==null && drawString==null)
{
// this.control.menuItem6.Enabled=false;
this.control.menuItem2.Enabled=false;
// this.control.menuItem7.Enabled=false;
// this.control.menuItem8.Enabled=false;
}
else
{
// this.control.menuItem6.Enabled=true;
this.control.menuItem2.Enabled=true;
// this.control.menuItem7.Enabled=true;
// this.control.menuItem8.Enabled=true;
}
this.control.menuItem7.Enabled=false;
this.control.menuItem8.Enabled=false;
}
else
{
ArrayList arrayList=new ArrayList();;
if( this.lastEdit is Line)
{
arrayList.Add((Line)this.lastEdit);
line=this.IsMouseOnLine(x,y,arrayList);
}
else if(this.lastEdit is Node)
{
arrayList.Add((Node)this.lastEdit);
node=this.IsMouseOnNode(x,y,arrayList);
}
else if(this.lastEdit is DrawString)
{
arrayList.Add((DrawString)this.lastEdit);
drawString=this.IsMouseOnDrawString(x,y,arrayList);
}
if(line==null && node==null && drawString==null)
{
this.control.menuItem2.Enabled=false;
this.control.menuItem7.Enabled=false;
this.control.menuItem8.Enabled=false;
}
else
{
this.control.menuItem2.Enabled=true;
this.control.menuItem7.Enabled=true;
this.control.menuItem8.Enabled=true;
}
}
if(drawString!=null)
{
this.objPrepareDel=drawString;
return true;
}
else if(node!=null)
{
this.objPrepareDel=node;
return true;
}
else if(line!=null)
{
this.objPrepareDel=line;
return true;
}
this.objPrepareDel=null;
return false;
}
public bool IsMouseOnAnySelectControl(int x,int y)
{
Line line=this.IsMouseOnLine(x,y,this.arrLineSelectList);
Node node=this.IsMouseOnNode(x,y,this.arrNodeSelectList);
DrawString drawString=this.IsMouseOnDrawString(x,y,this.arrDrawStringSelectList);
if(drawString!=null)
{
return true;
}
else if(node!=null)
{
return true;
}
else if(line!=null)
{
return true;
}
return false;
}
#endregion
#region 存储数组列的操作
/// <summary>
/// 重新排列元素ID
/// </summary>
/// <param name="arrayListIndex"></param>
public void FlashArrayList(int arrayListIndex)//arrayListIndex=0 表示线,arrayListIndex=1表示节点,arrayListIndex=2表示写字板
{
Line line;
Node node;
DrawString drawString;
if(arrayListIndex==0)
{
for(int i=0;i<this.arrLineList.Count;i )
{
line=(Line)this.arrLineList[i];
line.LineListIndex=i;
}
}
else if(arrayListIndex==1)
{
for(int i=0;i<this.arrNodeList.Count;i )
{
node=(Node)this.arrNodeList[i];
node.NodeListIndex=i;
}
}
else if(arrayListIndex==2)
{
for(int i=0;i<this.arrDrawStringList.Count;i )
{
drawString=(DrawString)this.arrDrawStringList[i];
drawString.DrawStrListIndex=i;
}
}
}
/// <summary>
/// 置顶
/// </summary>
public void SetTop()
{
if(this.objPrepareDel is Line)
{
Line line=(Line)this.objPrepareDel;
this.arrLineList.Add(line);
this.arrLineList.Remove(line);
this.FlashArrayList(0);
}
else if(this.objPrepareDel is Node)
{
Node node=(Node)this.objPrepareDel;
this.arrNodeList.Add(node);
this.arrNodeList.Remove(node);
this.FlashArrayList(1);
}
else if(this.objPrepareDel is DrawString)
{
DrawString drawString=(DrawString)this.objPrepareDel;
this.arrDrawStringList.Add(drawString);
this.arrDrawStringList.Remove(drawString);
this.FlashArrayList(2);
}
this.reDrawBitmap(this.graDrawPanel,10,10);
this.RefreshBackground();
GC.Collect();
}
/// <summary>
/// 置底
/// </summary>
public void SetDown()
{
if(this.objPrepareDel is Line)
{
Line line=(Line)this.objPrepareDel;
this.arrLineList.Remove(line);
this.arrLineList.Insert(0,line);
this.FlashArrayList(0);
}
else if(this.objPrepareDel is Node)
{
Node node=(Node)this.objPrepareDel;
this.arrNodeList.Remove(node);
this.arrNodeList.Insert(0,node);
this.FlashArrayList(1);
}
else if(this.objPrepareDel is DrawString)
{
DrawString drawString=(DrawString)this.objPrepareDel;
this.arrDrawStringList.Remove(drawString);
this.arrDrawStringList.Insert(0,drawString);
this.FlashArrayList(2);
}
this.reDrawBitmap(this.graDrawPanel,10,10);
this.RefreshBackground();
GC.Collect();
}
#endregion
#region 节点移动 线跟着改变 操作
/// <summary>
/// 获取连接到选中节点的线
/// </summary>
/// <param name="node"></param>
public void GetConnectNodeLine(Node node)//获取连接到选中节点的线
{
this.arrLineConnectNode.Clear();
for(int i=0;i<this.arrLineList.Count;i )
{
if(((Line)this.arrLineList[i]).FirstNode==node || ((Line)this.arrLineList[i]).SecondNode==node)
{
this.arrLineConnectNode.Add(((Line)this.arrLineList[i]));
}
}
}
/// <summary>
/// 动态改变节点大小,连接到上面的线跟着移动
/// </summary>
/// <param name="node">节点</param>
public void ReSizeNodeConLine(Node node)//动态改变节点大小,连接到上面的线跟着移动
{
Line line;
for(int i=0;i<this.arrLineConnectNode.Count;i )
{
line=((Line)this.arrLineConnectNode[i]);
if(line.FirstNode==node)
{
switch(line.FirNodeInterfaceIndex)
{
case 0: line.X0=node.X node.Width/2;line.Y0=node.Y; break;
case 1: line.X0=node.X; line.Y0=node.Y node.Height/2; break;
case 2: line.X0=node.X node.Width; line.Y0=node.Y node.Height/2; break;
case 3: line.X0=node.X node.Width/2; line.Y0=node.Y node.Height; break;
}
if(line.ObjectType==Line.DrawObjectType.DrawFoldLine)
{
switch(line.FirNodeInterfaceIndex)
{
case 0: line.Y1=node.Y; break;
case 1: line.Y1=node.Y node.Height/2; break;
case 2: line.Y1=node.Y node.Height/2; break;
case 3: line.Y1=node.Y node.Height; break;
}
}
}
if(line.SecondNode==node)
{
if(line.ObjectType==Line.DrawObjectType.DrawBeeLine)
{
switch(line.SecNodeInterfaceIndex)
{
case 0: line.X1=node.X node.Width/2; line.Y1=node.Y; break;
case 1: line.X1=node.X; line.Y1=node.Y node.Height/2; break;
case 2: line.X1=node.X node.Width; line.Y1=node.Y node.Height/2; break;
case 3: line.X1=node.X node.Width/2; line.Y1=node.Y node.Height; break;
}
}
else
{
switch(line.SecNodeInterfaceIndex)
{
case 0: line.X3=node.X node.Width/2; line.Y3=node.Y; line.Y2=node.Y; break;
case 1: line.X3=node.X; line.Y3=node.Y node.Height/2; line.Y2=node.Y node.Height/2; break;
case 2: line.X3=node.X node.Width; line.Y3=node.Y node.Height/2; line.Y2=node.Y node.Height/2; break;
case 3: line.X3=node.X node.Width/2; line.Y3=node.Y node.Height; line.Y2=node.Y node.Height; break;
}
}
}
}
}
#endregion
#region 节点大小的改变
/// <summary>
/// 节点大小改变的时候的X坐标的设定
/// </summary>
/// <param name="x"></param>
public void ChangeNodeX(int x)
{
if(x<this.iTempNodeX)
{
this.iNodeX=x;
this.iNodeWidth=this.iTempNodeX-x;
}
else
{
this.iNodeX=this.iTempNodeX;
this.iNodeWidth=x-this.iTempNodeX;
}
}
/// <summary>
/// 节点大小改变的时候的Y坐标的设定
/// </summary>
/// <param name="y"></param>
public void ChangeNodeY(int y)
{
if(y<this.iTempNodeY)
{
this.iNodeY=y;
this.iNodeHeight=this.iTempNodeY-y;
}
else
{
this.iNodeY=this.iTempNodeY;
this.iNodeHeight=y-this.iTempNodeY;
}
}
/// <summary>
/// 节点改变大小
/// </summary>
/// <param name="e"></param>
public void ChangeNodeSize(System.Windows.Forms.MouseEventArgs e)
{
if(this.iResizeNodeMouseIndex==0)
{
this.ChangeNodeX(e.X);
this.ChangeNodeY(e.Y);
}
else if(this.iResizeNodeMouseIndex==1)
{
this.ChangeNodeY(e.Y);
}
else if(this.iResizeNodeMouseIndex==2)
{
this.ChangeNodeX(e.X);
this.ChangeNodeY(e.Y);
}
else if(this.iResizeNodeMouseIndex==3)
{
this.ChangeNodeX(e.X);
}
else if(this.iResizeNodeMouseIndex==4)
{
this.ChangeNodeX(e.X);
}
else if(this.iResizeNodeMouseIndex==5)
{
this.ChangeNodeX(e.X);
this.ChangeNodeY(e.Y);
}
else if(this.iResizeNodeMouseIndex==6)
{
this.ChangeNodeY(e.Y);
}
else if(this.iResizeNodeMouseIndex==7)
{
this.ChangeNodeX(e.X);
this.ChangeNodeY(e.Y);
}
}
#endregion
#region 写字板大小的改变
/// <summary>
/// 写字板大小的改变 X坐标的设定
/// </summary>
/// <param name="x"></param>
public void ChangeDrawStringX(int x)
{
if(x<this.iTempDSX)
{
this.iDrawStringX=x;
this.iDrawStringWidth=this.iTempDSX-x;
}
else
{
this.iDrawStringX=this.iTempDSX;
this.iDrawStringWidth=x-this.iTempDSX;
}
}
/// <summary>
/// 写字板大小的改变 Y坐标的设定
/// </summary>
/// <param name="y"></param>
public void ChangeDrawStringY(int y)
{
if(y<this.iTempDSY)
{
this.iDrawStringY=y;
this.iDrawStringHeight=this.iTempDSY-y;
}
else
{
this.iDrawStringY=this.iTempDSY;
this.iDrawStringHeight=y-this.iTempDSY;
}
}
/// <summary>
/// 写字板大小的改变
/// </summary>
/// <param name="e"></param>
public void ChangeDSSize(System.Windows.Forms.MouseEventArgs e)
{
if(this.iResizeDSMouseIndex==0)
{
this.ChangeDrawStringX(e.X);
this.ChangeDrawStringY(e.Y);
}
else if(this.iResizeDSMouseIndex==1)
{
this.ChangeDrawStringY(e.Y);
}
else if(this.iResizeDSMouseIndex==2)
{
this.ChangeDrawStringX(e.X);
this.ChangeDrawStringY(e.Y);
}
else if(this.iResizeDSMouseIndex==3)
{
this.ChangeDrawStringX(e.X);
}
else if(this.iResizeDSMouseIndex==4)
{
this.ChangeDrawStringX(e.X);
}
else if(this.iResizeDSMouseIndex==5)
{
this.ChangeDrawStringX(e.X);
this.ChangeDrawStringY(e.Y);
}
else if(this.iResizeDSMouseIndex==6)
{
this.ChangeDrawStringY(e.Y);
}
else if(this.iResizeDSMouseIndex==7)
{
this.ChangeDrawStringX(e.X);
this.ChangeDrawStringY(e.Y);
}
}
#endregion
#region 改变折线
/// <summary>
/// 改变折线
/// </summary>
/// <param name="line">改变的折线</param>
/// <param name="iLinePointIndex">端点引起的变化 不为9的时候</param>
/// <param name="iLineIndex">边引起的变化 不为9的时候</param>
/// <param name="x">当前的鼠标X坐标 </param>
/// <param name="y">当前的鼠标Y坐标 </param>
public void ChangeFlodLine(Line line,int iLinePointIndex,int iLineIndex,int x,int y)
{
if(iLinePointIndex==0)
{
int distanceFir_Sec,distanceSec_3th;
if(!line.Modality)
{
distanceFir_Sec=Math.Abs(this.iLineSecondNodeX-this.iLineFirstNodeX);
distanceSec_3th=Math.Abs(this.iLine3thNodeY-this.iLineSecondNodeY);
if(distanceFir_Sec*2<distanceSec_3th)
{
line.Modality=true;
this.iLineSecondNodeX=x;
this.iLineSecondNodeY=(this.iLineFirstNodeY this.iLine4thNodeY)/2;
this.iLine3thNodeX=this.iLine4thNodeX;
this.iLine3thNodeY=this.iLineSecondNodeY;
this.selectPoint.LinePoint[1].X=this.iLineSecondNodeX;
this.selectPoint.LinePoint[1].Y=this.iLineSecondNodeY;
this.selectPoint.LinePoint[2].X=this.iLine3thNodeX;
this.selectPoint.LinePoint[2].Y=this.iLine3thNodeY;
}
}
else
{
distanceFir_Sec=Math.Abs(this.iLineSecondNodeY-this.iLineFirstNodeY);
distanceSec_3th=Math.Abs(this.iLine3thNodeX-this.iLineSecondNodeX);
if(distanceFir_Sec*2<distanceSec_3th)
{
line.Modality=false;
this.iLineSecondNodeX=(this.iLineFirstNodeX this.iLine4thNodeX)/2;
this.iLineSecondNodeY=this.iLineFirstNodeY;
this.iLine3thNodeX=this.iLineSecondNodeX;
this.iLine3thNodeY=this.iLine4thNodeY;
this.selectPoint.LinePoint[1].X=this.iLineSecondNodeX;
this.selectPoint.LinePoint[1].Y=this.iLineSecondNodeY;
this.selectPoint.LinePoint[2].X=this.iLine3thNodeX;
this.selectPoint.LinePoint[2].Y=this.iLine3thNodeY;
}
}
}
if(iLinePointIndex!=9 && iLineIndex==9)
{
if(iLinePointIndex==0)
{
if(!line.Modality)
{
this.iLineFirstNodeX=x;
this.iLineFirstNodeY=y;
this.iLineSecondNodeY=y;
this.selectPoint.LinePoint[0].X=x;
this.selectPoint.LinePoint[0].Y=y;
this.selectPoint.LinePoint[1].Y=y;
}
else
{
this.iLineFirstNodeX=x;
this.iLineFirstNodeY=y;
this.iLineSecondNodeX=x;
this.selectPoint.LinePoint[0].X=x;
this.selectPoint.LinePoint[0].Y=y;
this.selectPoint.LinePoint[1].X=x;
}
}
else if(iLinePointIndex==1)
{
if(!line.Modality)
{
this.iLineFirstNodeY=y;
this.iLineSecondNodeX=x;
this.iLineSecondNodeY=y;
this.iLine3thNodeX=x;
this.selectPoint.LinePoint[0].Y=y;
this.selectPoint.LinePoint[1].X=x;
this.selectPoint.LinePoint[1].Y=y;
this.selectPoint.LinePoint[2].X=x;
}
else
{
this.iLineFirstNodeX=x;
this.iLineSecondNodeX=x;
this.iLineSecondNodeY=y;
this.iLine3thNodeY=y;
this.selectPoint.LinePoint[0].X=x;
this.selectPoint.LinePoint[1].X=x;
this.selectPoint.LinePoint[1].Y=y;
this.selectPoint.LinePoint[2].Y=y;
}
}
else if(iLinePointIndex==2)
{
if(!line.Modality)
{
this.iLineSecondNodeX=x;
this.iLine3thNodeX=x;
this.iLine3thNodeY=y;
this.iLine4thNodeY=y;
this.selectPoint.LinePoint[1].X=x;
this.selectPoint.LinePoint[2].X=x;
this.selectPoint.LinePoint[2].Y=y;
this.selectPoint.LinePoint[3].Y=y;
}
else
{
this.iLineSecondNodeY=y;
this.iLine3thNodeX=x;
this.iLine3thNodeY=y;
this.iLine4thNodeX=x;
this.selectPoint.LinePoint[1].Y=y;
this.selectPoint.LinePoint[2].X=x;
this.selectPoint.LinePoint[2].Y=y;
this.selectPoint.LinePoint[3].X=x;
}
}
else if(iLinePointIndex==3)
{
if(!line.Modality)
{
this.iLine3thNodeY=y;
this.iLine4thNodeX=x;
this.iLine4thNodeY=y;
this.selectPoint.LinePoint[2].Y=y;
this.selectPoint.LinePoint[3].X=x;
this.selectPoint.LinePoint[3].Y=y;
}
else
{
this.iLine3thNodeX=x;
this.iLine4thNodeX=x;
this.iLine4thNodeY=y;
this.selectPoint.LinePoint[2].X=x;
this.selectPoint.LinePoint[3].X=x;
this.selectPoint.LinePoint[3].Y=y;
}
}
}
else if(iLinePointIndex==9 && iLineIndex!=9)
{
if(iLineIndex==0)
{
if(!line.Modality)
{
this.iLineFirstNodeY=y;
this.iLineSecondNodeY=y;
this.selectPoint.LinePoint[0].Y=y;
this.selectPoint.LinePoint[1].Y=y;
if(x<this.iLineFirstNodeX)
{
this.iLineFirstNodeX=x;
this.selectPoint.LinePoint[0].X=x;
}
}
else
{
this.iLineFirstNodeX=x;
this.iLineSecondNodeX=x;
this.selectPoint.LinePoint[0].X=x;
this.selectPoint.LinePoint[1].X=x;
}
}
else if(iLineIndex==1)
{
}
else if(iLineIndex==2)
{
if(!line.Modality)
{
this.iLine3thNodeY=y;
this.iLine4thNodeY=y;
this.selectPoint.LinePoint[2].Y=y;
this.selectPoint.LinePoint[3].Y=y;
if(x>this.iLine4thNodeX)
{
this.iLine4thNodeX=x;
this.selectPoint.LinePoint[3].X=x;
}
}
else
{
this.iLine3thNodeX=x;
this.iLine4thNodeX=x;
this.selectPoint.LinePoint[2].X=x;
this.selectPoint.LinePoint[3].X=x;
}
}
}
}
/// <summary>
/// 移动节点的时候改变折线的样子
/// </summary>
/// <param name="line">折线</param>
/// <param name="iLinePointIndex">端点ID </param>
/// <param name="node">连接到的节点</param>
/// <param name="iConnectIndex">节点上连接点的ID</param>
public void MoveNodeChangeLine(Line line,int iLinePointIndex,Node node,int iConnectIndex)
{
int x=0,y=0;
switch(iConnectIndex)
{
case 0:
x=this.iNodeX this.iNodeWidth/2;
y=this.iNodeY;
break;
case 1:
x=this.iNodeX;
y=this.iNodeY this.iNodeHeight/2;
break;
case 2:
x=this.iNodeX this.iNodeWidth;
y=this.iNodeY this.iNodeHeight/2;
break;
case 3:
x=this.iNodeX this.iNodeWidth/2;
y=this.iNodeY this.iNodeHeight;
break;
}
if(iLinePointIndex==0)
{
line.X0=x;
line.Y0=y;
if(!line.Modality)
{
line.Y1=y;
}
else
{
line.X1=x;
}
}
else if(iLinePointIndex==1)
{
line.X0=y;
line.X1=x;
line.Y1=y;
line.X2=x;
}
else if(iLinePointIndex==2)
{
line.X1=x;
line.X2=x;
line.Y2=y;
line.Y3=y;
}
else if(iLinePointIndex==3)
{
if(!line.Modality)
{
line.Y2=y;
}
else
{
line.X2=x;
}
line.X3=x;
line.Y3=y;
}
}
#endregion
#region 节点功能信息操作
/// <summary>
/// 属性栏的显示控制
/// </summary>
public void AttriShow()
{
if(this.lastEdit is Node || this.nodeSelectNode!=null)
{
this.control.epd_backGround.Hide();
this.control.epd_lineProperty.Hide();
this.control.epd_nodeProperty.Show();
this.control.epd_nodeProperty.Top=12;
this.control.epd_stringProperty.Hide();
Node node;
if(this.nodeSelectNode!=null)
{
node=this.nodeSelectNode;
this.control.node_X.Text="" this.iNodeX;
this.control.node_Y.Text="" this.iNodeY;
this.control.node_Width.Text="" this.iNodeWidth;
this.control.node_Height.Text="" this.iNodeHeight;
this.control.node_ID.Text="" node.NodeListIndex;
this.control.node_Type.Text="" getDefaultText(node.ObjectType);
this.control.node_Name.Text="" node.NodeText;
this.control.node_Size.Text="" node.TextSize;
this.control.node_Font_Color.BackColor=node.NodeTextColor;
if(node.ObjectType==Node.DrawObjectType.DrawRectangle ||node.ObjectType==Node.DrawObjectType.DrawEllipse)
{
this.control.node_Border_Color.Visible=true;
this.control.node_Fill_Color.Visible=true;
this.control.label11.Visible=true;
this.control.label12.Visible=true;
this.control.node_Border_Color.BackColor=node.BorderColor;
this.control.node_Fill_Color.BackColor=node.FillColor;
this.control.epd_nodeProperty.Height=280;
}
else
{
this.control.node_Border_Color.Visible=false;
this.control.node_Fill_Color.Visible=false;
this.control.label11.Visible=false;
this.control.label12.Visible=false;
this.control.epd_nodeProperty.Height=230;
}
}
else
{
node=(Node)this.lastEdit;
this.control.node_X.Text="" node.X;
this.control.node_Y.Text="" node.Y;
this.control.node_Width.Text="" node.Width;
this.control.node_Height.Text="" node.Height;
this.control.node_ID.Text="" node.NodeListIndex;
this.control.node_Name.Text="" node.NodeText;
this.control.node_Size.Text="" node.TextSize;
this.control.node_Font_Color.BackColor=node.NodeTextColor;
if(node.ObjectType==Node.DrawObjectType.DrawRectangle ||node.ObjectType==Node.DrawObjectType.DrawEllipse)
{
this.control.node_Border_Color.Visible=true;
this.control.node_Fill_Color.Visible=true;
this.control.label11.Visible=true;
this.control.label12.Visible=true;
this.control.node_Border_Color.BackColor=node.BorderColor;
this.control.node_Fill_Color.BackColor=node.FillColor;
this.control.epd_nodeProperty.Height=280;
}
else
{
this.control.node_Border_Color.Visible=false;
this.control.node_Fill_Color.Visible=false;
this.control.label11.Visible=false;
this.control.label12.Visible=false;
this.control.epd_nodeProperty.Height=230;
}
}
return;
}
else if(this.lastEdit is Line || this.lineSelectLine!=null)
{
this.control.epd_backGround.Hide();
this.control.epd_lineProperty.Show();
this.control.epd_lineProperty.Top=12;
this.control.epd_nodeProperty.Hide();
this.control.epd_stringProperty.Hide();
Line line;
if(this.lineSelectLine!=null)
{
line=this.lineSelectLine;
this.control.line_X0.Text="" line.X0;
this.control.line_Y0.Text="" line.Y0;
this.control.line_X1.Text="" line.X1;
this.control.line_Y1.Text="" line.Y1;
this.control.line_ID.Text="" line.LineListIndex;
this.control.line_color.BackColor=line.LineColor;
if(line.FirstNode!=null)
{
this.control.line_FirNode_ID.Text="" line.FirstNode.NodeListIndex;
}
else
{
this.control.line_FirNode_ID.Text="";
}
if(line.SecondNode!=null)
{
this.control.line_SecNode_ID.Text="" line.SecondNode.NodeListIndex;
}
else
{
this.control.line_SecNode_ID.Text="";
}
this.control.line_size.Text="" line.LineSize;
this.control.line_Type.Text=this.GetLineDefaultText(line.ObjectType);
this.control.tb_lineName.Text=line.Content;
}
else
{
line=(Line)this.lastEdit;
this.control.line_X0.Text="" line.X0;
this.control.line_Y0.Text="" line.Y0;
this.control.line_X1.Text="" line.X1;
this.control.line_Y1.Text="" line.Y1;
this.control.line_ID.Text="" line.LineListIndex;
if(line.FirstNode!=null)
{
this.control.line_FirNode_ID.Text="" line.FirstNode.NodeListIndex;
}
else
{
this.control.line_FirNode_ID.Text="";
}
if(line.SecondNode!=null)
{
this.control.line_SecNode_ID.Text="" line.SecondNode.NodeListIndex;
}
else
{
this.control.line_SecNode_ID.Text="";
}
this.control.line_size.Text="" line.LineSize;
this.control.line_Type.Text=this.GetLineDefaultText(line.ObjectType);
this.control.tb_lineName.Text=line.Content;
}
return;
}
else if(this.lastEdit is DrawString || this.drawStringSelectDS!=null)
{
this.control.epd_backGround.Hide();
this.control.epd_lineProperty.Hide();
this.control.epd_nodeProperty.Hide();
this.control.epd_stringProperty.Show();
this.control.epd_stringProperty.Top=12;
DrawString drawString;
if(this.drawStringSelectDS!=null)
{
drawString=this.drawStringSelectDS;
}
代码片段和文件信息
using System;
using System.Collections;
namespace GDIDrawFlow
{
///
/// ArrayData 的摘要说明。
///
///
[Serializable()]
public class ArrayData
{
public ArrayList arrLineList;//线的数组
public ArrayList arrNodeList;//节点的数组
public ArrayList arrDrawStringList;//写字板的数组
public ArrayList arrLineSelectList;//线的数组
public ArrayList arrNodeSelectList;//节点的数组
public ArrayList arrDrawStringSelectList;//写字板的数组
public ArrayList arrLineNotSelectList;//没有被选择的线的数组
public ArrayList arrNodeNotSelectList;//没有被选择的节点的数组
public ArrayList arrDrawStringNotSelectList;//没有被选择的写字板的数组
public ArrayList arrLineConnectNode;//连接到活动节点的线
public ArrayData()
{
//
// TODO: 在此处添加构造函数逻辑
//
this.arrLineList=new ArrayList()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1322 2006-08-18 00:03 GDI流程图控件c#源码\GDIDrawFlow\ArrayData.cs
文件 1925 2006-08-15 16:34 GDI流程图控件c#源码\GDIDrawFlow\AssemblyInfo.cs
文件 774144 2013-08-19 12:12 GDI流程图控件c#源码\GDIDrawFlow\bin\Debug\GDIDrawFlow.dll
文件 626176 2013-08-19 12:12 GDI流程图控件c#源码\GDIDrawFlow\bin\Debug\GDIDrawFlow.pdb
文件 40240 2006-11-18 13:27 GDI流程图控件c#源码\GDIDrawFlow\bin\Debug\GDIDrawFlow.tlb
文件 326 2006-08-20 15:41 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Asunder.cur
文件 326 2006-08-20 15:41 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Converge.cur
文件 326 2006-08-20 15:41 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Data.cur
文件 326 2006-08-20 15:41 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Ellipse.cur
文件 326 2006-08-20 15:41 GDI流程图控件c#源码\GDIDrawFlow\Cursors\end.cur
文件 326 2006-08-20 15:42 GDI流程图控件c#源码\GDIDrawFlow\Cursors\FlodLine.cur
文件 326 2006-08-20 15:42 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Gather.cur
文件 326 2006-08-20 15:42 GDI流程图控件c#源码\GDIDrawFlow\Cursors\General.cur
文件 326 2006-08-20 15:42 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Gradation.cur
文件 326 2006-08-20 15:42 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Judgement.cur
文件 326 2006-08-20 15:43 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Line.cur
文件 326 2006-08-20 15:34 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Pencil.cur
文件 518 2006-08-20 15:34 GDI流程图控件c#源码\GDIDrawFlow\Cursors\PolyHandle.cur
文件 326 2006-08-20 15:34 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Rectangle.cur
文件 326 2006-08-20 15:43 GDI流程图控件c#源码\GDIDrawFlow\Cursors\SpecificallyOperation.cur
文件 326 2006-08-20 15:43 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Start.cur
文件 326 2006-08-20 15:43 GDI流程图控件c#源码\GDIDrawFlow\Cursors\Synchronization.cur
文件 152548 2010-08-05 13:32 GDI流程图控件c#源码\GDIDrawFlow\DrawFlowControl.cs
文件 115218 2010-08-05 13:23 GDI流程图控件c#源码\GDIDrawFlow\DrawFlowControl.resx
文件 37328 2006-11-18 14:40 GDI流程图控件c#源码\GDIDrawFlow\DrawFlowGroup.cs
文件 73333 2006-11-18 14:33 GDI流程图控件c#源码\GDIDrawFlow\DrawFlowGroup.resx
文件 3111 2006-08-21 17:04 GDI流程图控件c#源码\GDIDrawFlow\DrawFlowTable.cs
文件 214569 2006-08-25 13:42 GDI流程图控件c#源码\GDIDrawFlow\Drawob
文件 2435 2006-08-18 23:53 GDI流程图控件c#源码\GDIDrawFlow\DrawString.cs
文件 29492 2006-08-24 22:26 GDI流程图控件c#源码\GDIDrawFlow\flowAttribute.cs
............此处省略165个文件信息
- 上一篇:关于在C#程序中,调用摄像头的问题
- 下一篇:C# 贝叶斯算法 垃圾邮件检测
相关资源
- C#联通网络宽带测试 拨号
- C#百度指数抓取方法(2012年版本已失
- C# 隐藏某个磁盘分区
- C# 读取并编辑window系统的右键菜单
- C#自定义屏保(不断滚动的文字)
- C#winform打印指定区域 -控件拖动 -设置
- C#使用Hook进行改键
- 提供C#调用系统API函数弹出或收起光驱
- 通过C#自带的头文件(类)获取Windo
- C#获取电脑CPU以及内存使用率
- 利用uu云打码平台的lib实现的c#打码平
- tf-idf一种计算方法
- C# pop3 邮件接收程序
- C# 邮件群发示例 源码下载18952
- 动态抓取IPC#实现
- XXTEA算法的C#实现和JS实现,可以互相
- C# 飞行棋 游戏源码(面向对象入门)
- 基于WinPcap的C# ARP欺骗软件().rar
- C#网络应用编程 矩阵并行计算练习
- 《C#版Ftp软件源码》
-
C# 播放铃声(AxWindowsMediaPla
yer)最新 - C# 把图片显示成椭圆形状
- C# 水平交错效果显示图像
- winform 浮雕效果的图像
- c# 底片效果显示图像就像旧式相机的
- 积木效果显示图像
- C# 隐形窗体 (没有边框,没有标题栏
- browerPhotoC#网页截图(不打开网页)
- C# 模拟时钟(自绘Graphics)
- C#之WPF重绘动态正弦余弦曲线
评论
共有 条评论