如下面的例子:
public void LookForLine(string sID,sLineIDs)//sID为管线段ID,sLineIDs为已查管线ID组合
{
string tempLineID = sLineIDs + " " + sID;
objLine obj = objLine(arrLine[sID]);//获取管线对象
ArrayList aA = obj.A;//获取管线对象中的相邻ID属性
for(int i=0;i <aA.Length;i++)
{
if(//这里要做一下处理,避免同一个ID重复调用,而引发死循环)
{
if(aA[i]==_sID)//代表已经找到当前管线段
{
_FindLineIDs = tempLineID;
}
else
{
LookForLine(aA[i],tempLineID);
}
}
}
}
如何写OBJLine里面的类的Arraylist?
public void LookForLine(string sID,sLineIDs)//sID为管线段ID,sLineIDs为已查管线ID组合
{
string tempLineID = sLineIDs + " " + sID;
objLine obj = objLine(arrLine[sID]);//获取管线对象
ArrayList aA = obj.A;//获取管线对象中的相邻ID属性
for(int i=0;i <aA.Length;i++)
{
if(//这里要做一下处理,避免同一个ID重复调用,而引发死循环)
{
if(aA[i]==_sID)//代表已经找到当前管线段
{
_FindLineIDs = tempLineID;
}
else
{
LookForLine(aA[i],tempLineID);
}
}
}
}
如何写OBJLine里面的类的Arraylist?
public class objLine
{
private string _sid = "";
public objLine(string sid)
{
_sid = sid;
}
private ArrayList _A;
public ArrayList A
{
get
{
_A = new ArrayList();
//根据_sid设置_A
return _A;
}
}
}
画直线Line的类里面没有写arraylist 把画直线的类贴出来。
根据某直线的ID返回与之相连的直线 需要计算出来。
--------------------------------------
你需要存放这n条直线。然后才能统计啊。是否必须用arraylist?
--------------------------------------
不是。但arrayList较好。画直线Line的类里面没有写arraylist。
--------------------------------------
需要你自己写了。我现在的主要目的是,写两个函数,1)、根据某直线的ID返回直线;
--------------------------------------
遍历arraylist(如果你是用arraylist存储线的话)2)根据某直线的ID返回与之相连的直线;
--------------------------------------
用1)获得直线,再遍历arraylist(如果你是用arraylist存储线的话)求相交的直线了。
望给予答复。多谢!
-------------------------------------
我都给你答复了。不用客气了,分数给我就好了。
{
private Point startPoint;
private Point endPoint; private const string entryStart = "Start";
private const string entryEnd = "End"; /// <summary>
/// Graphic objects for hit test
/// </summary>
private GraphicsPath areaPath = null; private Pen areaPen = null;
private Region areaRegion = null;
public DrawLine()
{
startPoint.X = 0;
startPoint.Y = 0;
endPoint.X = 1;
endPoint.Y = 1;
ZOrder = 0; Initialize();
}
public DrawLine(int x1, int y1, int x2, int y2)
{
startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
ZOrder = 0; Initialize();
} public DrawLine(int x1, int y1, int x2, int y2, DrawingPens.PenType p)
{ startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
DrawPen = DrawingPens.SetCurrentPen(p);
PenType = p;
ZOrder = 0; Initialize();
} public DrawLine(int x1, int y1, int x2, int y2, Color lineColor, int lineWidth)
{
startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
Color = lineColor;
PenWidth = lineWidth;
ZOrder = 0; Initialize();
}
public override void Draw(Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen;
if (DrawPen == null)
pen = new Pen(Color, PenWidth);
else
pen = (Pen)DrawPen.Clone();
GraphicsPath gp = new GraphicsPath();
gp.AddLine(startPoint, endPoint);
// Rotate the path about it's center if necessary
if (Rotation != 0)
{
RectangleF pathBounds = gp.GetBounds();
Matrix m = new Matrix();
m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
gp.Transform(m);
}
g.DrawPath(pen, gp);
gp.Dispose();
pen.Dispose();
} /// <summary>
/// Clone this instance
/// </summary>
public override DrawObject Clone()
{
DrawLine drawLine = new DrawLine();
drawLine.startPoint = startPoint;
drawLine.endPoint = endPoint;
//drawLine.ID=
FillDrawObjectFields(drawLine);
return drawLine;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.Collections; namespace WindowsApplication34
{
public partial class Form1 : Form
{
// 存个数
static ArrayList TotalLines = new ArrayList(); public Form1()
{
InitializeComponent(); Graphics g = this.CreateGraphics();
DrawingPens.PenType PT=new DrawingPens.PenType();
PT.Name="AliceBlue";
DrawLine DL=new DrawLine(10,10,50,50,PT);
DL.Draw(g);
TotalLines.Add(DL);
DL = new DrawLine(120, 120, 550, 250, PT);
DL.Draw(g);
TotalLines.Add(DL);
DL = new DrawLine(1, 15, 150, 350);
DL.Draw(g);
TotalLines.Add(DL);
DL = new DrawLine(11, 11, 52, 53);
DL.Draw(g);
TotalLines.Add(DL);
DL = new DrawLine(50, 40, 110, 120);
DL.Draw(g);
TotalLines.Add(DL);
}
} public abstract class DrawObject
{
public int ZOrder;
public Color Color;
public int PenWidth;
public Pen DrawPen;
public int Rotation;
public abstract void Draw(Graphics g);
public abstract DrawObject Clone();
public DrawingPens.PenType PenType;
public void Initialize()
{
} public void FillDrawObjectFields(DrawLine dr)
{
}
} public class DrawingPens
{
static Pen Current;
public class PenType
{
public String Name;
} public static Pen SetCurrentPen(PenType P)
{
if (P.Name == "AliceBlue")
Current=Pens.AliceBlue;
return Current;
} public Object Clone()
{
return null;
}
} public class DrawLine : DrawObject
{
private Point startPoint;
private Point endPoint; private const string entryStart = "Start";
private const string entryEnd = "End"; /// <summary>
/// Graphic objects for hit test
/// </summary>
private GraphicsPath areaPath = null; private Pen areaPen = null;
private Region areaRegion = null; public DrawLine()
{
startPoint.X = 0;
startPoint.Y = 0;
endPoint.X = 1;
endPoint.Y = 1;
ZOrder = 0; Initialize();
} public DrawLine(int x1, int y1, int x2, int y2)
{
startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
ZOrder = 0; Initialize();
} public DrawLine(int x1, int y1, int x2, int y2, DrawingPens.PenType p)
{ startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
DrawPen = DrawingPens.SetCurrentPen(p);
PenType = p;
ZOrder = 0; Initialize();
} public DrawLine(int x1, int y1, int x2, int y2, Color lineColor, int lineWidth)
{
startPoint.X = x1;
startPoint.Y = y1;
endPoint.X = x2;
endPoint.Y = y2;
Color = lineColor;
PenWidth = lineWidth;
ZOrder = 0; Initialize();
}
public override void Draw(Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen;
if (DrawPen == null)
pen = new Pen(Color, PenWidth);
else
pen = (Pen)DrawPen.Clone();
GraphicsPath gp = new GraphicsPath();
gp.AddLine(startPoint, endPoint);
// Rotate the path about it's center if necessary
if (Rotation != 0)
{
RectangleF pathBounds = gp.GetBounds();
Matrix m = new Matrix();
m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
gp.Transform(m);
}
g.DrawPath(pen, gp);
gp.Dispose();
pen.Dispose();
} /// <summary>
/// Clone this instance
/// </summary>
public override DrawObject Clone()
{
DrawLine drawLine = new DrawLine();
drawLine.startPoint = startPoint;
drawLine.endPoint = endPoint;
//drawLine.ID=
FillDrawObjectFields(drawLine);
return drawLine;
}
}
}
你可以参考下这个设计器的方法!
这样就可以很好统计了!