Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6374
  • Last Modified:

How to right align text in a winform label c#

Hi all,

I've been searching everywhere to find how I can right align text in a label. Found lost of answers for Asp.Net but not for Winforms.
I've tried to play around with the property Text-Align en RightToLeft but no luck. Tried 2 solutions I found on the net but no luck.

I have a bunch of labels wich display currency so they must be right aligned.
vb:         x
vb:      xxx
vb:        xx

Does anyone have an idea how to to this?

Grts
0
Pit76
Asked:
Pit76
  • 2
2 Solutions
 
CebikCommented:
labelCurrency.Autosize = false;
labelCurrency.TextAlign  = TopRight;
0
 
abelCommented:
What you are after is the AutoSize property. Once you set that to False, you can use TextAlign.
0
 
abelCommented:
right, precisely like Cebik says :)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If the "vb:" is part of the string then it'd probably easier to move those into their own labels that are right aligned and then use different labels JUST for the data.  Otherwise you'd have to use a fixed width font and "pad" the string in-between the "vb:" and the data...or use Graphics.MeasureString() to figure out how many spaces are needed to line them up properly with a normal font...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now