c#创建PDA应用程序的柱形图控件(五)

double a1=double.Parse(System.Convert.ToString(this.LineCount-1));
double a2=double.Parse(this.mMaxYValue.ToString());
double a=System.Math.Round(a2/a1,1);

for(int i=0;i {
string Text=System.Convert.ToString(a*(i+1));
int txtWidth=(int)objGraph.mGraphics.MeasureString(Text,this.mTextFont).Width;
p1.X=p.X-txtWidth-this.mLenght;;
p1.Y-=this.BetweenLineHeight;
this.objGraph.DrawText(Text,Color.Black,this.mTextFont,p1.X,p1.Y);
}
}
}
//求数据列的和
private double SumColumn(DataTable dt,string ColumnName)
{
double Sum=0.0;
foreach(DataRow dr in dt.Rows)
{
Sum+=System.Convert.ToDouble(dr[ColumnName]);
}
return Sum;
}
}

#region
public class MyGraph
{
//网络水平线中二线之间的高
//int BetweenLineHeight=20;
//最大MaxYCount:线数
// int MaximumY=10;
// int Lenght=5;
// int Width=200;
// int Height=300;
// bool IsShowGrid=true;

public Graphics mGraphics;

//背景色
// public Color BackColor= System.Drawing.SystemColors.Control;
// //X轴颜色
// public Color AxesXColor=System.Drawing.SystemColors.HighlightText;
// //Y轴颜色
// public Color AxesYColor=System.Drawing.SystemColors.Info;

//黑色笔
private Pen mBlackPen = new System.Drawing.Pen(Color.FromArgb(0,0,0));
//网格线笔
private Pen mGridPen= new System.Drawing.Pen(Color.FromArgb(127, 127, 127));
//Color BackColor= System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));

public MyGraph()
{
//mGraphics=this.CreateGraphics(); //
// TODO: 在此处添加构造函数逻辑
//
}

//由左下顶点与宽、高画颜色为color的平行四边形
public void DrawRectangle3DTop(Color color, Point LeftUnderPoint,int Width,int Height)
{
try
{

//计算左上顶点
Point p1=new Point ();
p1.X=LeftUnderPoint.X+Height;
p1.Y=LeftUnderPoint.Y-Height;

//计算右上顶点
Point p2=new Point ();
p2.X=LeftUnderPoint.X+Width+Height;
p2.Y=LeftUnderPoint.Y-Height;

//计算右下顶点
Point p3=new Point ();
p3.X=LeftUnderPoint.X+Width;
p3.Y=LeftUnderPoint.Y;
Point[] curvePoints =
{
LeftUnderPoint,
p1,
p2,
p3
};

// Define fill mode.
//FillMode newFillMode = FillMode.Winding;
// Fill polygon to screen.
// Create solid brush.
SolidBrush Brush = new SolidBrush(color);
mGraphics.FillPolygon(Brush, curvePoints);
//mGraphics.FillPolygon(Brush, curvePoints, newFillMode);
//画边框
mGraphics.DrawPolygon(this.mBlackPen, curvePoints);
}
catch(Exception ex)
{
string str=ex.Message;
}

}
//由左下顶点与宽、高画颜色为color的平等四边形
public void DrawRectangle3DRight(Color color, Point LeftUnderPoint,int Width,int Height)
{
try
{
// Create solid brush.
SolidBrush Brush = new SolidBrush(color);

//计算左上顶点
Point p1=new Point ();
p1.X=LeftUnderPoint.X;
p1.Y=LeftUnderPoint.Y-Height;

//计算右上顶点
Point p2=new Point ();
p2.X=p1.X+Width;
p2.Y=p1.Y-Width;

//计算右下顶点
Point p3=new Point ();
p3.X=LeftUnderPoint.X+Width;
p3.Y=LeftUnderPoint.Y-Width;
Point[] curvePoints =
{
LeftUnderPoint,
p1,
p2,
p3
};

// Define fill mode.
//FillMode newFillMode = FillMode.Winding;
// Fill polygon to screen.
mGraphics.FillPolygon(Brush, curvePoints);
//画边框
mGraphics.DrawPolygon(this.mBlackPen, curvePoints);
//mGraphics.FillPolygon(Brush, curvePoints, newFillMode);
}
catch(Exception ex)
{
string str=ex.Message;
}
}

//由左上角顶点与宽、高画颜色为color的平行四边形
public void DrawRectangle(Color color, Point P,int Width,int Height)
{
Rectangle Rectangle1=new Rectangle( P.X,P.Y, Width,Height);

// Create solid brush.
SolidBrush Brush = new SolidBrush(color);
// Fill polygon to screen.
mGraphics.FillRectangle(Brush, Rectangle1);

//画边框
mGraphics.DrawRectangle(this.mBlackPen,Rectangle1);

}

//由左下顶点与长、宽、高画颜色为color的立方图形(3D)
public void DrawCube(Color color, Point LeftUnderPoint,int Lenght,int Width,int Height)
{
// Create solid brush.
SolidBrush Brush = new SolidBrush(color);

  <p>Point LeftTopPoint= LeftUnderPoint; <br>
    LeftTopPoint.Y-= Height; </p>
  <p>DrawRectangle3DTop(color,LeftTopPoint,Width,Lenght); <br>
    DrawRectangle(color,LeftTopPoint,Width,Height); </p>
  <p>Point RightP=LeftUnderPoint; <br>
    RightP.X+=Width; <br>
    DrawRectangle3DRight(Color.Black,RightP,Lenght,Height); <br>
    } </p>
  <p>//画X轴 <br>
    public void DrawAxesX(Color color, Point  p,int Width,int Height) <br>
    { <br>
    DrawRectangle3DTop(color,p,Width,Height); <br>
    } </p>
  <p>//画Y轴 <br>
    public void DrawAxesY(Color color, Point  p,int Width,int Height) <br>
    { <br>
    DrawRectangle3DRight(color,p,Width,Height); <br>
    } </p>
  <p>//由顶点与长、宽、高画颜色为color,背景色为的BackColor图表(3D) <br>
    public void DrawPDAChart(Color  GridLineColor,Color AxesXColor,Color AxesYColor,_ <br>
    Color  BackColor,Point p,int Lenght,int Width,int Height,bool IsShowAxesX,bool  IsShowAxesY) <br>
    { <br>
    if(IsShowAxesX) <br>
    { <br>
    //画X轴 <br>
    DrawAxesX(AxesXColor,p,Width,Lenght); <br>
    } <br>
    if(IsShowAxesY) <br>
    { <br>
    //画Y轴 <br>
    DrawAxesY(AxesYColor,p,Lenght,Height); <br>
    } </p>
  <p>////画图形区 <br>
    Point pRectangle=p; <br>
    pRectangle.X+=Lenght; <br>
    pRectangle.Y-=Lenght; <br>
    pRectangle.Y-=Height; <br>
    DrawRectangle(BackColor,pRectangle,Width,Height); <br>
    } <br>
    //画一条水平网络线与对应的折线 <br>
    public void DrawGridLine(Color  GridLineColor,Point p,int Width,int Lenght) <br>
    { <br>
    //Draw the Y scale; <br>
    Point EndP=p; <br>
    EndP.X+=Width; <br>
    Pen pen=new Pen( GridLineColor); <br>
    //this.mGraphics.DrawLine(pen,p,EndP); <br>
    //水平线 <br>
    this.mGraphics.DrawLine(pen,p.X,p.Y,EndP.X,EndP.Y  ); <br>
    //左折线 <br>
    this.mGraphics.DrawLine(pen,p.X,p.Y,EndP.X-Lenght,EndP.Y+Lenght  ); <br>
    } <br>
    //画所有水平网络线 <br>
    //p:起始点;Width:线宽;BetweenHeight:二线之间高,Count:线数 <br>
    public void DrawGridLines(Color  GridLineColor,Point p,int Width,int Lenght,int BetweenHeight,int Count) <br>
    { <br>
    Pen pen=new Pen( GridLineColor); <br>
    for(int i=0;i { <br>
    //DrawGridLine(GridLineColor,p,Width,Lenght); <br>
    //水平线 <br>
    this.mGraphics.DrawLine(pen,p.X,p.Y,p.X+Width,p.Y  ); <br>
    //左折线 <br>
    this.mGraphics.DrawLine(pen,p.X-Lenght+1,p.Y+Lenght,p.X,p.Y); <br>
    p.Y-=BetweenHeight; <br>
    } <br>
    } </p>
  <p>//在位置(x,y)处以颜色color、字体font写文本text <br>
    public void DrawText(string text,Color  color, Font font,int x,int y) <br>
    { <br>
    // Create solid brush. <br>
    SolidBrush Brush = new SolidBrush(color); <br>
    this.mGraphics.DrawString(text, font,  Brush, x ,y); <br>
    } </p>
  <p>//由点p(矩形左上角点),宽pieWidth,高pieHeight,颜色color画馅饼图 <br>
    public void DrawCake(Color color,Point  p,int pieWidth,int pieLenght,int pieHeight) <br>
    { <br>
    Pen PenBlack=new Pen( Color.Black); <br>
    //黑色最下面的椭圓 <br>
    Rectangle rc1 =new  Rectangle(p.X,p.Y+pieHeight,pieWidth,pieLenght); <br>
this.mGraphics.DrawEllipse(PenBlack,rc1); </p></td>