473,883 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.TextAlig n = System.Drawing. ContentAlignmen t.MiddleCenter
label2.TextAlig n = System.Drawing. ContentAlignmen t.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 4547
Forgive me if I'm missing somthing, but what you seem to be asking for is
Alignment.LeftC enter... :)

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

Josh
Microsoft.com Tools
"Mark Urish" <an*******@disc ussions.microso ft.com> wrote in message
news:E7******** *************** ***********@mic rosoft.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.TextAlig n = System.Drawing. ContentAlignmen t.MiddleCenter;
label2.TextAlig n = System.Drawing. ContentAlignmen t.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*******@disc ussions.microso ft.com> wrote in message
news:50******** *************** ***********@mic rosoft.com...
Thanks for the quick response.

Yes, LeftCenter would work except that I also have BorderStyle=Fix edSingle. 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.LeftC enter... :)

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

Josh
Microsoft.com Tools
"Mark Urish" <an*******@disc ussions.microso ft.com> wrote in message
news:E7******** *************** ***********@mic rosoft.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.TextAlig n = System.Drawing. ContentAlignmen t.MiddleCenter;
> label2.TextAlig n = System.Drawing. ContentAlignmen t.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*******@disc ussions.microso ft.com> wrote in message
news:E7******** *************** ***********@mic rosoft.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.TextAlig n = System.Drawing. ContentAlignmen t.MiddleCenter;
label2.TextAlig n = System.Drawing. ContentAlignmen t.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
2017
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 program. Any suggestions? Thanks, Dolphe.
1
9048
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 Settings\\XX\\Desktop\\- Copy of TestingFolder -\\jjjj hihi.doc"); where there is 2 space between dash and "Copy of TestingFolder", but after going through Runtime.getRuntime().exec(arg), it chopes off one space and
3
10708
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 fields: BuildName and RoadName. Both have the following properties: size 50, not indexed, not required, allowed zero length. Some records have BuildName, RoadName as null, some have content. No content is 50 chr long. When i run a Len(BuildName)...
3
5844
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 in essence just removing the trailing space from each line?
3
8942
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 a test"
1
123175
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
3013
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 the string to check character one by one. Support not using MFC.
2
3146
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
2615
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 GCTAG TAATC Please help me, i am a biology student! Thanks!
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11142
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
9574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7971
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
7129
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
5797
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...
1
4612
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
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3233
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.