Label alignment issue

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Label alignment issue

 
0
  #1
Sep 26th, 2009
Hi all,
Left of a TextBox I have a Label and the text changes during a run so I want the text to be right aligned. So I used the TextAlign property of a Label and set it to MiddleRight. It does not work. Looked for an answer, could not find one. Don't no what I am overlooking here
Any reply is more than welcome.
Last edited by ddanbe; Sep 26th, 2009 at 4:22 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 213
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: Label alignment issue

 
0
  #2
Sep 26th, 2009
Check out this thread:
http://www.daniweb.com/forums/thread209516.html


I believe there is some confusion in the beginning of the thread concerning what right-to-left means, but go down toward the bottom and also sknake attached a project that demonstrates the label expansion.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Label alignment issue

 
0
  #3
Sep 26th, 2009
Yes looked at it but I did not read it all the way down. Thanks DdoubleD!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,464
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Label alignment issue

 
0
  #4
Sep 26th, 2009
Yeah I submitted a bug report to Microsoft and they confirmed it was a bug, but not important enough to fix.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Label alignment issue

 
1
  #5
Sep 27th, 2009
Hi DdoubleD and Scott,

Think I found another solution to the problem, I forgot about Label all the way and derived a class from Panel:
  1. class LabelPanel : Panel
  2. {
  3. public LabelPanel()
  4. {
  5. text = string.Empty;
  6. font = new Font("Ariel", 8f);
  7. fontcolor = Color.Black;
  8. }
  9.  
  10. public string text { get; set; }
  11. public Font font { get; set; }
  12. public Color fontcolor { get; set; }
  13. //more or less properties here don't know yet
  14.  
  15. protected override void OnPaint(PaintEventArgs e)
  16. {
  17. base.OnPaint(e);
  18. Graphics G = e.Graphics;
  19. Brush brush = new SolidBrush(fontcolor);
  20. Rectangle rec = new Rectangle(new Point(0, 0), this.Size);
  21. StringFormat strfmt = new StringFormat();
  22. strfmt.Alignment = StringAlignment.Far; // means Right if RightLeft is true
  23. G.DrawString(text, font, brush, rec, strfmt);
  24. }
  25. }
And this is how I call it in a Form:
  1. LabelPanel LP = new LabelPanel();
  2. public Form1()
  3. {
  4. InitializeComponent();
  5. LP.Size = new Size(290, 20);
  6. this.Controls.Add(LP);
  7. }
  8.  
  9. private void SetLabelTexts(List<string> SL)
  10. {
  11. LP.text = SL[0];
  12. //Many more LabelPanels here
  13. Refresh();
  14. }

Works like a charm!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 213
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: Label alignment issue

 
0
  #6
Sep 27th, 2009
LabelPanel huh...very interesting!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,464
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Label alignment issue

 
0
  #7
Sep 27th, 2009
That is a neat approach
Last edited by sknake; Sep 27th, 2009 at 6:10 pm.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 313
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Label alignment issue

 
0
  #8
Sep 27th, 2009
Thanks for your answers!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

Tags
alignment, label, text

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum


Views: 842 | Replies: 7
Thread Tools Search this Thread



Tag cloud for alignment, label, text
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC