tags:

views:

126

answers:

5

Hi, I am making an application in which the label keeps scrolling up. The problem I have is I want to do right alignment so that I get "." in a sequence like

Basket..............
Ball................
keyboard............

Can anyone help me with this please?

I have tried this, but it isn't working for me,

for (int u = textBox1.Length; u = 40 ; u++)
{
    strDotsBuilder.Append(".");
}
A: 

Try this:

for (int u = textBox1.Length; u < 40 ; u++)
{
    strDotsBuilder.Append(".");
}

The second statement in a for loop is the condition that determines whether or not to keep looping. In your case you were assigning "40" to u rather that checking it as an upper bound for the loop.

Andrew Hare
so what should i do now ?
Umair
Did you try my example?
Andrew Hare
+8  A: 

That really doesn't needs to be in a for loop...
Why don't you use the padLeft function of a string?

"myString".PadLeft(40,'.');
Edit:
You need "myString".PadRight(40,'.');

Stormenet
Should be PadRight()
Robert Koritnik
Oh, yes :p (I need 15 chars to add the comment, so here's some rubbisch words :p)
Stormenet
You mean 'rubbish', I think.
Jeff
Yea, my rubbisch was rubbish, good point!
Stormenet
+1  A: 

Stormenet's suggestion should point you in the right direction. However when I see your example sequence, I'd probably go for the padRight variant.

Rob van Groenewoud
A: 

I hope your for loop is correctly written, since the second for-loop argument should be boolean resulting statement. Yours is not.

So instead:

for (int u = textBox1.Length; u = 40 ; u++)

you should write

for (int u = textBox1.Length; u <= 40 ; u++)
Robert Koritnik
== is not the correct operator, either. It should be <, as the second argument for a for loop is the condition under which you loop. In your corrected sample, it will only loop when u is equal to 40.
JustLoren
A: 

Using ellipses or full stops as a visual indicator will only work correctly in a console or other app using a monospaced font, and only then when the width of the label is sensitive to the user's system font sizes.

If you are creating a web app, you may have better luck with a bottom border style for your label to create that leading line, a right-floated image that clips at the edge of the label, or a repeating background image in the label's parent overridden by the label text.

richardtallent