| | |
Label alignment issue
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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.
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
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jul 2009
Posts: 972
Reputation:
Solved Threads: 213
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.
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.
Yeah I submitted a bug report to Microsoft and they confirmed it was a bug, but not important enough to fix.
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:
And this is how I call it in a Form:
Works like a charm!
Think I found another solution to the problem, I forgot about Label all the way and derived a class from Panel:
c# Syntax (Toggle Plain Text)
class LabelPanel : Panel { public LabelPanel() { text = string.Empty; font = new Font("Ariel", 8f); fontcolor = Color.Black; } public string text { get; set; } public Font font { get; set; } public Color fontcolor { get; set; } //more or less properties here don't know yet protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics G = e.Graphics; Brush brush = new SolidBrush(fontcolor); Rectangle rec = new Rectangle(new Point(0, 0), this.Size); StringFormat strfmt = new StringFormat(); strfmt.Alignment = StringAlignment.Far; // means Right if RightLeft is true G.DrawString(text, font, brush, rec, strfmt); } }
c# Syntax (Toggle Plain Text)
LabelPanel LP = new LabelPanel(); public Form1() { InitializeComponent(); LP.Size = new Size(290, 20); this.Controls.Add(LP); } private void SetLabelTexts(List<string> SL) { LP.text = SL[0]; //Many more LabelPanels here Refresh(); }
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
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- Text Alignment Issue (JavaScript / DHTML / AJAX)
- Gridbag Layout Probelm [Code Included] (Java)
- ideas (PHP)
- Any assistance on MIPS sorting (Assembly)
- Html alignment issue (HTML and CSS)
Other Threads in the C# Forum
- Previous Thread: How to programmatically create User Profile [C#]?
- Next Thread: auto scaling in web application
Views: 842 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for alignment, label, text
ads adsense alignment array assembly based basic black buy c# c++ color compression console createrange() design dictionary display edit editor events external file font foreach game getselection google import javascript keyboard label lines link parse perl port portfolio print printer pygame python read revenue review richtextbox rpg search speech split technology text textbox txttoxmlconverter unicode unit vb2008 visual website win32 xml







