正如问题所表明的,这就是我正在尝试做的事情,任何人都可以看到一段时间以来一直在摆弄它。目前它只显示文本文件中的前 3 个数字,当我按下下一个按钮时,我希望它转到下一个 3,但它似乎不起作用..
namespace GPSProject
{
public partial class Form1 : Form
{
private int count;
internal dataPoints myDataPoints;
public Form1()
{
myDataPoints = new dataPoints();
InitializeComponent();
}
private void buttonNext_Click(object sender, EventArgs e)
{
{
Button b = (Button)sender;
if (b.Name.Equals("buttonNext"))
{
count++;
if (count == (myDataPoints.Count))
count = 0;
}
else
{
count--;
if (count < 0)
count = myDataPoints.Count - 1;
}
dataPoint a = myDataPoints.getItem(count);
textBoxLatitude.Text = a.CurLatitude;
textBoxLongtitude.Text = a.CurLongtitude;
textBoxElevation.Text = a.CurElevation;
}
}
}
}
上面是我的表单窗口,下面是我的数据点
namespace GPSProject
{
class dataPoints
{
public int Count { get { return Points.Count; } }
List<dataPoint> Points;
//string p;
public dataPoints(/*string path*/)
{
Points = new List<dataPoint>();
// p = path;
TextReader tr = new StreamReader(/*p*/"C:/Test.txt");
string input;
while ((input = tr.ReadLine()) != null)
{
string[] bits = input.Split(',');
dataPoint a = new dataPoint(bits[0], bits[1], bits[2]);
Points.Add(a);
}
tr.Close();
}
internal dataPoint getItem(int p)
{
if (p < Points.Count)
{
return Points[p];
}
else
return null;
}
}
}