3

我正在使用Kinectand 可以将跟踪坐标保存到文本文件中,但我需要为每个 X 和 Y 坐标添加水平(从左到右)的文本,以便绘制图形。目前,文本如下所示:

2:58:22 PM

Head X      314

Head Y      250

2:58:22 PM

Head X      314

Head Y      251

但我试图这样得到它:

2:58:22 PM               2:58:23 PM

Head X  1   2   3   4  5   6   7  8  9 

Head Y  1   2   3   4  5   6   7  8  9 

这是我保存到文本文件的代码:

StreamWriter sw = File.AppendText("Text.txt");
sw.WriteLine(DateTime.Now.ToLongTimeString());

sw.WriteLine("Head X   " + "\t" + TextBox21.Text);
sw.WriteLine("Head Y   " + "\t" + TextBox41.Text);

sw.WriteLine("Shoulder X" + "\t" + TextBox22.Text);
sw.WriteLine("Shoulder Y" + "\t" + TextBox42.Text);

sw.WriteLine("ShoulderLeft X" + "\t" + TextBox23.Text);
sw.WriteLine("ShoulderLeft Y" + "\t" + TextBox43.Text);

sw.WriteLine("ShoulderRight X" + "\t" + TextBox24.Text);
sw.WriteLine("ShoulderRight Y" + "\t" + TextBox44.Text);

sw.WriteLine("ElbowLeft X" + "\t" + TextBox25.Text);
sw.WriteLine("ElbowLeft Y" + "\t" + TextBox45.Text);

sw.WriteLine("ElbowRight X" + "\t" + TextBox26.Text);
sw.WriteLine("ElbowRight Y" + "\t" + TextBox46.Text);

sw.WriteLine("WristLeft X" + "\t" + TextBox27.Text);
sw.WriteLine("WristLeft Y" + "\t" + TextBox47.Text);

sw.WriteLine("WristRight X" + "\t" + TextBox28.Text);
sw.WriteLine("WristRight Y" + "\t" + TextBox48.Text);

sw.WriteLine("HandLeft X" + "\t" + TextBox29.Text);
sw.WriteLine("HandLeft Y" + "\t" + TextBox49.Text);

sw.WriteLine("HandRight X" + "\t" + TextBox30.Text);
sw.WriteLine("HandRight Y" + "\t" + TextBox50.Text);

sw.WriteLine("Spine X   " + "\t" + TextBox31.Text);
sw.WriteLine("Spine Y   " + "\t" + TextBox51.Text);

sw.WriteLine("HipCenter X" + "\t" + TextBox32.Text);
sw.WriteLine("HipCenter Y" + "\t" + TextBox52.Text);

sw.WriteLine("HipLeft X" + "\t" + TextBox33.Text);
sw.WriteLine("HipLeft Y" + "\t" + TextBox53.Text);

sw.WriteLine("HipRight X" + "\t" + TextBox34.Text);
sw.WriteLine("HipRight Y" + "\t" + TextBox54.Text);

sw.WriteLine("KneeLeft X" + "\t" + TextBox35.Text);
sw.WriteLine("KneeLeft Y" + "\t" + TextBox55.Text);

sw.WriteLine("KneeRight X" + "\t" + TextBox36.Text);
sw.WriteLine("KneeRight Y" + "\t" + TextBox56.Text);

sw.WriteLine("AnkleLeft X" + "\t" + TextBox37.Text);
sw.WriteLine("AnkleLeft Y" + "\t" + TextBox57.Text);

sw.WriteLine("AnkleRight X" + "\t" + TextBox38.Text);
sw.WriteLine("AnkleRight Y" + "\t" + TextBox58.Text);

sw.WriteLine("FootLeft X" + "\t" + TextBox39.Text);
sw.WriteLine("FootLeft Y" + "\t" + TextBox59.Text);

sw.WriteLine("FootRight X" + "\t" + TextBox40.Text);
sw.WriteLine("FootRight Y" + "\t" + TextBox60.Text);

sw.Close();         
4

3 回答 3

0

sw.Write将允许您编写内联文本。

WriteLine创建一个换行符。

于 2013-04-24T15:00:23.853 回答
0

跳过 WriteLine 的“Line”部分,直接使用 Write?

于 2013-04-24T15:00:28.500 回答
0

我在这里可能错了,但我想也许你只是想使用Write()而不是WriteLine()

WriteLine()将在末尾添加换行符。所以你想要的是如下:

sw.Write("Head X   " + "\t" + TextBox21.Text);

您可能还需要考虑添加一个额外的分隔符,但这取决于您需要什么作为输出。

于 2013-04-24T15:00:32.607 回答