[求助]大家看看我的程序的溢出错误!我调了一天了!就是提示溢出错误!
using System;using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace StockChart
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class StockChart : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public class Stock
{
public Color m_Color;
public String m_Ticker;
public float[] m_Price;
}
private float m_MaxY = 100F;
private float m_MinY = 0F;
private float m_MaxX = 1;
private float m_MinX = 10;
private float m_TickX = 1;
private float m_TickY = 10;
private ArrayList m_StockList;
private Rectangle m_PaintRectangle;
public float MaxY
{
set{m_MaxY = value;}
}
public float MinY
{
set{m_MinY = value;}
}
public float MaxX
{
set{m_MaxX = value;}
}
public float MinX
{
set{m_MinX = value;}
}
public void AddStock(Stock aStock)
{
m_StockList.Add(aStock);
}
public float TickX
{
set{m_TickX = value;}
}
public float TickY
{
set{m_TickY = value;}
}
PointF PixelPoint(PointF valuePoint)
{
PointF newPoint = new PointF();
newPoint.X = m_PaintRectangle.X + (valuePoint.X - m_MinX) *
m_PaintRectangle.Width / (m_MaxX - m_MinX);
newPoint.Y = m_PaintRectangle.Bottom - (valuePoint.Y - m_MinY)*
m_PaintRectangle.Height / (m_MaxY - m_MinY);
return newPoint;
}
public StockChart()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
m_StockList = new ArrayList();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "绘制股票图";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// StockChart
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(492, 366);
this.Controls.Add(this.button1);
this.Name = "StockChart";
this.Text = "股票图表";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new StockChart());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.MaxX = 2000;
this.MinX = 1996;
this.MaxY = 140;
this.MaxY = 0;
//Add stock for MicroSoft and Intel
StockChart.Stock aStock = new StockChart.Stock();
aStock.m_Ticker = "MSFT";
aStock.m_Color = Color.Red;
aStock.m_Price = new float[5]{36.1F,71.3F,119.35F,45.2F,64.9F};
this.AddStock(aStock);
aStock = new StockChart.Stock();
aStock.m_Ticker = "INTEL";
aStock.m_Color = Color.Blue;
aStock.m_Price = new float[5]{10.3F,23.34F,22.2F,8.78F,20.19F};
Graphics aGraphics = this.CreateGraphics();
//calculate the location and size of the rectangle
//within which we want to draw the graph...
m_PaintRectangle = new Rectangle(this.ClientRectangle.Location,this.ClientRectangle.Size);
Size s = new Size(12,14);
m_PaintRectangle.Inflate(-(6 * s.Width), -(6 * s.Height));
aGraphics.DrawRectangle(Pens.Black, m_PaintRectangle);
//Creat horizontal gridlines...
float y;
Pen aGridPen = new Pen(Color.Black);
aGridPen.DashStyle = DashStyle.Dot;
for(y = m_MinY + m_TickY; y <= m_MaxY; y += m_TickY)
{
aGraphics.DrawLine(aGridPen,
PixelPoint(new PointF(m_MinX,y)),
PixelPoint(new PointF(m_MaxX,y)));
}
aGridPen.Dispose();
//Creat the y axis tick marks...
for(y = m_MinY;y < m_MaxY; y += m_TickY)
{
PointF xaxisPoint = PixelPoint(new PointF(m_MinX,y));
aGraphics.DrawLine(Pens.Black,
xaxisPoint,
new PointF(xaxisPoint.X - s.Width / 2,xaxisPoint.Y));
}
//Creat x-axois tick marks00
float x;
for(x = m_MinX; x <= m_MaxX; x += m_TickX)
{
PointF yaxisPoint = PixelPoint(new PointF(x,m_MinY));
aGraphics.DrawLine(Pens.Black,
yaxisPoint,
new PointF(yaxisPoint.X,
yaxisPoint.Y + s.Height / 2));
}
//plot the stock data
foreach(Stock newStock in m_StockList)
{
Pen aPen = new Pen(newStock.m_Color,2);
float startX = m_MinX;
PointF startPoint = new PointF(m_MinX,newStock.m_Price[0]);
PointF endPoint = new PointF(m_MinX,newStock.m_Price[0]);
foreach(float price in newStock.m_Price)
{
endPoint.Y = price;
aGraphics.DrawLine(aPen,
PixelPoint(startPoint),
PixelPoint(endPoint));
startPoint = endPoint;
endPoint.X += 1;
}
aPen.Dispose();
}
} //end of button handler
}
}