473,289 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Center a string with a trailing space

I want to center-align the text in 2 Label controls, and I want the 1st char of their text to line up
------------------------------------------------------------------------------
label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

label1.Text = "IDLE"; //4 char strin
label2.Text = "RUN ";//4 char string,
//but trailing space ignored and it is centered as thoug
//it has only 3 chars
------------------------------------------------------------------------------

Is there a way to make the Label control center "Run " (with a trialing space) as though it is 4 chars long

thanks
Mark Urish
Nov 15 '05 #1
3 4501
Forgive me if I'm missing somthing, but what you seem to be asking for is
Alignment.LeftCenter... :)

Can't you align the labels so that the start on the same X?

Josh
Microsoft.com Tools
"Mark Urish" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I want to center-align the text in 2 Label controls, and I want the 1st char of their text to line up: -------------------------------------------------------------------------- ----- label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

label1.Text = "IDLE"; //4 char string
label2.Text = "RUN ";//4 char string,
//but trailing space ignored and it is centered as though //it has only 3 chars.
-------------------------------------------------------------------------- -----
Is there a way to make the Label control center "Run " (with a trialing space) as though it is 4 chars long?
thanks,
Mark Urish

Nov 15 '05 #2
Humm,

Well, I've been playing around and it dosn't look like the Label really
wants to do that... but you already knew that...

You could build your own label control that dosn't trim the traling spaces;

Derive from Panel, override OnPaint and use the Graphics object to measure
and draw your string in the right place... but that might be over kill...

I also tried putting each label on it's own panel, but couldn't get the
docking or anchoring scheme that worked right...

Dunno doode... :)

Josh
Microsoft.com Tools

"Mark Urish" <an*******@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
Thanks for the quick response.

Yes, LeftCenter would work except that I also have BorderStyle=FixedSingle. I want to the text to be roughly centered inside
the border. I realize that I could do this by using LeftCenter and
prepending spaces so that the text is approximately centered, but the Label
is anchored in a user-control and may be resized. I don't want to have to
compute the number of spaces necessary to keep the text centereed in the
frame. That's what MiddleCenter is supposed to do :).
Any further suggestions are much appreciated!
Mark Urish

----- Josh [MS.Com] wrote: -----

Forgive me if I'm missing somthing, but what you seem to be asking for is Alignment.LeftCenter... :)

Can't you align the labels so that the start on the same X?

Josh
Microsoft.com Tools
"Mark Urish" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
> I want to center-align the text in 2 Label controls, and I want the 1st
char of their text to line up:


--------------------------------------------------------------------------
-----
> label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
> label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
>> label1.Text = "IDLE"; //4 char string > label2.Text = "RUN ";//4 char string,
> //but trailing space ignored and it

is centered as though
> //it has only 3 chars.



--------------------------------------------------------------------------
----- >> Is there a way to make the Label control center "Run " (with a
trialing
space) as though it is 4 chars long? >> thanks,

> Mark Urish


Nov 15 '05 #3
Hi,

OK, after reading this thread and the replies, I've got a
thought on it, though I haven't tried it. What I would do in
this situation is to (if possible) figure out what the center
would be based on the width of the control, set the
alignment to left, and add the appropriate amount of
spaces to the beginning of the text in both controls. I did
try adding the spaces, and this seems to work.

Now, you might not get it *exactly* in the center every
time, but with some fiddling I'm sure you could find a way
to calculate it so that each one had the same amount of
leading spaces when resized or whatever. That is, as
long as BOTH controls are aligned with one another. If
that's not a feasible alternative, then I'm sorry, but right
now that is the only way I can see to handle it correctly.

Beyond that, It's anybody's guess!

"Mark Urish" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I want to center-align the text in 2 Label controls, and I want the 1st char of their text to line up: -------------------------------------------------------------------------- ----- label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

label1.Text = "IDLE"; //4 char string
label2.Text = "RUN ";//4 char string,
//but trailing space ignored and it is centered as though //it has only 3 chars.
-------------------------------------------------------------------------- -----
Is there a way to make the Label control center "Run " (with a trialing space) as though it is 4 chars long?
thanks,
Mark Urish

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dolphe Tilly | last post by:
Hi All, I need to set some string array space "REPLACE ME" aside. In the compiled version I wish to replace the text string for something else using a hex-editor. Reason: password acces to the...
1
by: aa | last post by:
Anybody know the solution to trailing space in argument of Runtime.getRuntime().exec(arg), Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler C:\\Documents and...
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
3
by: shaft | last post by:
hi i have the following code : string addrress; cin >> address; cout << address; if I enter any string with space in between , it will save the first word only. e.g. if i enter "this is...
1
by: Konstantinos Pachopoulos | last post by:
Hi, is there something corresponding to the java String.trim() method, ie trim start and trailing space/tab chars from string? say convert " asdf " to "asdf"? Thnx
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I think in built-in C/C++ functions, there is no direct function call to trim heading and trailing space characters, right? So, we have to implement it manually by iterating...
2
by: skumari | last post by:
Hello I am new user of this Forum.Can anyone help me regarding "How tp Replace a new line character "\n" in a string with space or ," Using Javascript. Please reply me ASAP.
2
by: nhbach | last post by:
I have a long string in db $code = "ACTGTCTACTGGTCTAGCTAGTCATGCTAGTAATCG" How to separate a long string to short string with space each 5 character? Example: ACTGT CTACT GGTCT AGCTA GTCAT...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.