473,788 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteL ine("");" command, lets say i want the message
to appear centered when running the program. Thank you so much! ;)
Apr 2 '08 #1
2 3932
Not built in (AFAIK) - but you can just pad it manually:

static void Main()
{
WriteLineCenter ed("foo {0}", "bar");
}
static void WriteLineCenter ed(string format, params object[]
args)
{
string value = string.Format(f ormat, args);
int padding = (Console.Window Width - value.Length) / 2;
if (padding 0)
{
Console.Write(n ew string(' ',padding));
}
Console.WriteLi ne(value);
}
Apr 2 '08 #2
On Apr 2, 2:04*am, Fernando Rios
<FernandoR...@d iscussions.micr osoft.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.WriteL ine("");" 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4768
by: Mario | last post by:
i have three rows on my main site i want that the middle-row resizes (only height) depending on the windows size i know it is possible in javascript, but i dont know how ot do it im more like server-side scripting type of guy <table align="center" width="100%" height="100%"><tr align="center"
1
2584
by: James Carnley | last post by:
I am learning how to use windows forms and I have come across a small problem. Whenever I run my program it opens a console window before launching the windows form. The console doesnt go away until the program exits. When you use VS.net to make a windows application it makes a form without a console and I dont know why. What specifies whether a program starts with a console or not? I know that this code is probobly not right but I...
2
2282
by: Bonnett | last post by:
I have made a simple console application that creates a webpage from my playlist, then uploads it to my webhost. I decided to convert it to a windows service and use the FileSystemWatcher to monitor the playlist file, this is where i became stuck. I know the service detects changes to the playlist as when running the Change event of FileSystemWatcher, I add an item to the event log. I've tried making the service without including the...
6
3236
by: Mark Allison | last post by:
Hi, I have an application that I want to be to run in Console mode and GUI mode. If no params are entered, I want the GUI fired up, if params are entered, then go into console mode. I believe I have all the code set up to do this, however when I issue a Console.WriteLine instruction, nothing gets written to the console. In fact, the command prompt comes back before the program has finished executing. What do I need to do?
9
7273
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
8
17160
by: RTT | last post by:
i'm writing a windows form but codebased a iwant to run the code as a different user. like in a webapplication you can impersonate a user so the website does not run on the standard ASP.NET user. is it possible to do the same for a windows form and define a user codebased and run the code like that user is running the application.
7
2069
by: programming | last post by:
Hi all, i have been having trouble with a login script that works on my windows machine, however when i upload it to the Unix server through VPN, the same script won't work! It won't parse member.txt properly i think. The password and usernames i am using are at the bottom of this post. Each time i go to login on the unix server, it clears the username and password field. I have been attempting to solve the problem, but have been...
4
10517
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it doesn't seem to write to the screen in the way I would expect. The output is:
5
1435
AutumnsDecay
by: AutumnsDecay | last post by:
Hey there. So over the time I've been gone, I got engaged. I am now making an information site for my and my fiances wedding. The problem is that on every page I use a table inside a DIV. I do this to make everything look nice and sorted. It display perfectly in IE, Safari, FF for Mac, but not in FF for windows. In FF for windows, the "content" div doesn't even recognize that the table exists as a table (similar to containing div...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.