[英]Reading and using Screen Coordinates from txt file
Heya我一直在做這個項目。 鏈接到Pastebin
我想知道是否可以從中讀取坐標
txtX2,txtY2 TextBox's
而是來自文本文件。
而是使用文本文檔中的那些坐標。
如果你不明白我的意思,請回復:P,但如果你看一下你可能會理解的代碼。
謝謝 :)
假設您已使用以下格式將坐標保存在文本文件中:
<Coordinate1>,<Coordinate2>
你可以做:
String contents = System.IO.File.ReadAllText();
String[] coordinates = contents.Split(',');
現在coordinates[0]
是X
, coordinates[1]
是Y
如果文件中有多行,並且您想在每個計時器滴答中讀取一行,您實際上可以執行以下操作:
// class variable
private StreamReader reader;
// in constructor
reader = System.IO.File.OpenText("PATH");
// in destructor
reader.close();
// in timer
String line;
if ((line = reader.ReadLine()) != null)
{
String[] coordinates = line.split(',');
// now coordinates[0] is X and coordinates[1] is Y
}
這是一個如何從文本文件中讀取的非常簡單的示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.