C#文本对齐权控制台 [英] C# Align Text Right in Console

查看:153
本文介绍了C#文本对齐权控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有我的方式来对齐文本到我的控制台应用程序的右侧?我想在同一行,但在右边打印一个字符串[OK]。就像你看到引导Linux发行版的时候。

Is there a way for me to align text to the right side of my Console Application? I want to print a String with "[ok]" on the same line but on the right hand side. Like you see when booting a Linux Distro.

推荐答案

我会建议使用诅咒作为@Oded说。

I would suggest using curses as @Oded said.

如果你真的不希望使用任何第三方库,你可以使用 Console.BufferWidth 来获得控制台的大小,然后 Console.Console.CursorLeft 来设置列位置。

If you really don't want to use any third party libraries, you can use Console.BufferWidth to get size of console and then Console.Console.CursorLeft to set column position.

Console.CursorLeft = Console.BufferWidth - 4;
Console.Write("[ok]");



上面的打印[确定]在当前行的结尾,使光标在第一列中,下一行

The above prints [ok] at the end of the current line, leaving cursor at the first column, next line

这篇关于C#文本对齐权控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆