Reputation: 19
I am new to c #. I am creating a simple console application. my task is to make a mark in a certain place in the console. and erase the old position every time. It works. But there was a problem. When using console.clear (); there is simply a transfer to a new frame with the ability to view the old position of my previously marked point.
scrolling occurs after each click
how to remove previous console values?
MyCode:
using System;
namespace paint
{
class Point
{
public int x {get;set;}
public int y {get;set;}
//public int mark_y {get;set;}
//public int mark_x {get;set;}
protected int[] Position(){
this.x = x;
this.y = y;
//this.mark_x = mark_x;
//this.mark_y = mark_y;
return new int [] {this.x,this.y};
}
}
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Point position = new Point{x = 10, y = 5};
do
{
Console.SetCursorPosition(position.x, position.y);
System.ConsoleKeyInfo console_key = Console.ReadKey(true);
if(console_key.Key == ConsoleKey.DownArrow && position.y >= 0 && position.y <= 9){
position.y += 1;
}
if(console_key.Key == ConsoleKey.UpArrow && position.y <= 10 && position.y >= 2){
position.y -= 1;
}
if(console_key.Key == ConsoleKey.LeftArrow && position.x <= 19 && position.x >= 1){
position.x -= 1;
}
if(console_key.Key == ConsoleKey.RightArrow && position.x >= 0 && position.x <= 18){
position.x += 1;
}
if(console_key.Key == ConsoleKey.Spacebar){
//position.mark_x = position.x;
//position.mark_y = position.y;
Console.Clear();
Console.SetCursorPosition(position.x, position.y);
Console.WriteLine("█");
}
} while (true);
}
}
}
Upvotes: 0
Views: 111
Reputation: 56
You can do this by creating a new console every time you reset the position by using Console Functions. Detach the current console with FreeConsole and then create a new console using AllocConsole.
Upvotes: 1