Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

Ho can I just right align a special text/word like "A"?

Thanks
Posted
Comments
Karen Mitchelle 9-May-14 4:57am    
Hi.
I think you are pertaining to the 'Text Align' thing?
You can see that on the property window of your project. On the right side.

You can apply :

ASP.NET
<asp:textbox id="txtTest" style="text-align: right;" runat="server" xmlns:asp="#unknown"></asp:textbox>


The word can any thing a number or character it will work for both.
 
Share this answer
 
As a WinForms alternative to Solution 2
Me.TextBox1.TextAlign = HorizontalAlignment.Right
or as Karen Mitchelle [^] pointed out in the comments, you can change this property at design time.

For either ASP code-behind or winforms...

If the text is to be used for other purposes you can "right-align" the string itself by padding left with spaces e.g.
Dim s As String = "Some Text".PadLeft(15, " ")
produces
|      Some Text|

For example you could use this method to right align items in a combobox like this
VB
For i = 1 To 10
        Me.ComboBox1.Items.Add(i.ToString().PadLeft(15, " "))
Next
 
Share this answer
 
v2
Comments
Pouya Mozafar 11-May-14 10:41am    
If you try the code Dim s As String = "Some Text".PadLeft(15, " ") you see that it will be go to the top and will delete all texts in the top.

and I just want to right align it at that line it is there and I want to RIGHT ALIGN not padleft.....

Thanks for your attention
CHill60 11-May-14 11:07am    
You've confused me. There is no concept of "go to the top" of a String variable - it has a value (or not).
PadLeft gives the effect of right aligning text within the available "space" - see the combobox example
Some sort of context to your question might help - what controls are you wanting to right align, is this WinForms or Web or what??
Pouya Mozafar 11-May-14 11:10am    
I'm sorry for confuse.But if I have these texts:

B


a
and I want to right align it with that code this will be the result:

a
no B!

It is a winforms.
CHill60 11-May-14 11:13am    
This is no clearer. Is this text in a textbox, richtextbox, listview, label???? Where did the "no" and the "!" come from? Try posting the code that you use to populate this text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900