資源簡介
【實例截圖】
【核心代碼】
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重繪動態正弦余弦曲線