0

I'm trying to create a map for an RPG game and it was originally built for a console application. The code for the map is here: 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. 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:

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!

Simon Karlsson
  • 4,090
  • 22
  • 39
  • How do you want to format the text? See this question to find out how to format text in `RichTextBox` control - http://stackoverflow.com/questions/4077582/format-text-in-rich-text-box Then you can save the contents of `richTextBox1.Rtf` variable to text file. – Alex Feb 05 '16 at 10:51
  • I essentially want it to look like this - http://postimg.org/image/rrwgregwz/ - I'm not sure how I would do this using the question you posted (I'm extremely new to C# too..) – JamieBrace Feb 05 '16 at 11:05
  • This is how it should look - http://postimg.org/image/3y3ityjfv/ and this is how it currently looks - http://postimg.org/image/owfzvbdp5/ – JamieBrace Feb 05 '16 at 11:37

1 Answers1

0

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. Once you have read this string back you must once again convert it to a textrange.

Remember to include Using System.IO

Links which will help you learn about these things are below:

Stream Reader

Stream Writer

Text Range