0

Hi i have to display various symbols at different places in the console window using x and y coordinates however i am not allowed to use the Console.SetCursorPosition() method. This is how it was done with the method

        string k="$";
        string l="%";

        Console.SetCursorPosition(30, 20);
        Console.Write(k);

        Console.SetCursorPosition(15, 6);
        Console.Write(l);

        Console.ReadLine(); 

I need a way around using the Console.SetCursorPosition() method. Any alternatives will help i was told to use treat it like looping through a multi-dimensional array but i have made no headway. thanks alot for all the help in advanced

chridam
  • 100,957
  • 23
  • 236
  • 235
user2735869
  • 23
  • 1
  • 2
  • See if this [SO question](http://stackoverflow.com/questions/2754518/how-can-i-write-fast-colored-output-to-console) Helps – Mark Hall Aug 31 '13 at 20:53

1 Answers1

2

I don't think you have any method replacing SetCursorPosition (also the CursorLeft and CursorTop properties). However I understand that you don't want the cursor to jump on the window when you Write something. Here is a work around for you:

public static void WriteAt(int left, int top, string s){
   int currentLeft = Console.CursorLeft;
   int currentTop = Console.CursorTop;
   Console.CursorVisible = false;//Hide cursor
   Console.SetCursorPosition(left, top);
   Console.Write(s);
   Console.SetCursorPosition(currentLeft, currentTop);
   Console.CursorVisible = true;//Show cursor back
}
//Use it
WriteAt(30, 20, k);
WriteAt(15, 6, l);

The point is we hide the cursor before changing its position and write all string, after finishing writing string, we move it back to the old position and show it back.

NOTE: Anyway, for your requirement which restricts you from using SetCursorPosition (looks like some kind of riddle/challenge :), you can always use Console.CursorLeft and Console.CursorTop instead to change the cursor position.

King King
  • 61,710
  • 16
  • 105
  • 130