[英]How do I output a character array to a textfile?
I'm trying to create a map for an RPG game and it was originally built for a console application. 我正在尝试为RPG游戏创建地图,它最初是为控制台应用程序构建的。 The code for the map is here: http://pastebin.com/R6jyT3vw
该地图的代码在这里: http : //pastebin.com/R6jyT3vw
The main method was used to Initialise the map, Add Rooms and then display the Map. 主要方法用于初始化地图,添加房间,然后显示地图。 I'm trying to create an RPG using windows forms, and I wanted to display this map in a richtextbox.
我正在尝试使用Windows窗体创建一个RPG,并且我想在RichTextBox中显示此地图。 I figure the easiest way to do this would be to output the array to a text file and then set the textbox to read that file.
我认为最简单的方法是将数组输出到文本文件,然后将文本框设置为读取该文件。
Is this possible to do? 这可能吗? I've tried a few things such as a TextWriter:
我尝试了一些诸如TextWriter的操作:
MapForm mapForm = new MapForm();
Console.SetOut(new ControlWriter(mapForm.rtbMap));
mapForm.Show();
string locationName = _player.CurrentLocation.Name;
_player.CurrentLocation.DisplayMap(locationName);
But this doesn't exactly format how I want it to. 但这并不能完全格式化我想要的格式。 Any ideas?
有任何想法吗?
Thanks! 谢谢!
You need to create a Textrange
as the flowdocument
which is bound to the richtextbox.content
and then use a streamWriter
to write this to a text document and a streamReader
to read the string
back from the document. 您需要创建一个
Textrange
作为flowdocument
这势必给richtextbox.content
,然后使用streamWriter
写这一个文本文件和streamReader
读取string
从文件回来。 Once you have read this string
back you must once again convert it to a textrange
. 一旦读回该
string
,就必须再次将其转换为textrange
。
Remember to include Using System.IO
记住要包括
Using System.IO
Links which will help you learn about these things are below: 以下链接可帮助您了解这些内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.