Windows Console App Align

  • Thread starter Thread starter Fernando Rios
  • Start date Start date
F

Fernando Rios

Hi, I'm a rookie about C# and im starting developing some Basic Console
Aplications, but i was just wondering if there's a way to center a message
when using the "Console.WriteLine("");" command, lets say i want the message
to appear centered when running the program. Thank you so much! ;)
 
Not built in (AFAIK) - but you can just pad it manually:

static void Main()
{
WriteLineCentered("foo {0}", "bar");
}
static void WriteLineCentered(string format, params object[]
args)
{
string value = string.Format(format, args);
int padding = (Console.WindowWidth - value.Length) / 2;
if (padding > 0)
{
Console.Write(new string(' ',padding));
}
Console.WriteLine(value);
}
 
Hi, I'm a rookie about C# and im starting developing some Basic Console
Aplications, but i was just wondering if  there's a way to center a message
when using the "Console.WriteLine("");" command, lets say i want the message
to appear centered when running the program. Thank you so much! ;)

Hi,

Not really, you see int he console you can only isntruct to display a
text, but you have no control of how to do it. I'm not aware of any
library that allows you to control and format the console.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top