【发布时间】:2021-10-05 12:32:16
【问题描述】:
我是 C# 的新手。我正在创建一个简单的控制台应用程序。我的任务是在控制台的某个地方做一个标记。并每次删除旧位置。有用。但有一个问题。当使用console.clear();只需转移到新框架即可查看我之前标记点的旧位置。
每次点击后都会发生滚动
如何删除以前的控制台值?
我的代码:
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);
}
}
}
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/questions/3244976/…
-
在 ubuntu 上不起作用
-
我的错误:“仅在 'windows' 上受支持。
标签: c# ubuntu console console-application