471,330 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Windows Console App Align

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! ;)
Apr 2 '08 #1
2 3855
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);
}
Apr 2 '08 #2
On Apr 2, 2:04*am, Fernando Rios
<FernandoR...@discussions.microsoft.comwrote:
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.
Apr 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James Carnley | last post: by
6 posts views Thread by Mark Allison | last post: by
9 posts views Thread by SP | last post: by
7 posts views Thread by programming | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.