# HG changeset patch # User sl # Date 1408697734 -7200 # Node ID a9048f35097565ba7b7ac1147c6ac7701edbc200 # Parent 1864e4fd172847a524c004a862115828844745d7 Now that we fixed that nasty iStringFormat static bug we could cleanup and simplify our alginment code. diff -r 1864e4fd1728 -r a9048f350975 Server/MarqueeLabel.cs --- a/Server/MarqueeLabel.cs Fri Aug 22 10:44:45 2014 +0200 +++ b/Server/MarqueeLabel.cs Fri Aug 22 10:55:34 2014 +0200 @@ -20,7 +20,6 @@ private SizeF iTextSize; private SizeF iSeparatorSize; private SizeF iScrollSize; - private ContentAlignment iRequestedContentAlignment; [Category("Appearance")] [Description("Separator in our scrolling loop.")] @@ -84,7 +83,6 @@ PixelsLeft = 0; CurrentPosition = 0; iBrush = new SolidBrush(ForeColor); - iRequestedContentAlignment = TextAlign; //Following is needed if we ever switch from Label to Control base class. //Without it you get some pretty nasty flicker @@ -225,8 +223,6 @@ CurrentPosition = 0; LastTickTime = DateTime.Now; PixelsLeft = 0; - //Reset text align - //TextAlign = iRequestedContentAlignment; //For all string measurements and drawing issues refer to the following article: // http://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number @@ -246,19 +242,9 @@ if (NeedToScroll()) { //Always align left when scrolling - //Somehow draw string still takes into our control alignment so we need to set it too - //ContentAlignment original = TextAlign; - TextAlign = ContentAlignment.MiddleLeft; - //Make sure our original text alignment remain the same even though we override it when scrolling - //iRequestedContentAlignment = original; - //iStringFormat will get updated in OnTextAlignChanged - //StringFormat.Alignment = StringAlignment.Near; + iStringFormat.Alignment = StringAlignment.Near; } - else - { - //We don't need to scroll so make sure the desired alignment is used - TextAlign = iRequestedContentAlignment; - } + } protected override void OnTextChanged(EventArgs e) @@ -277,13 +263,13 @@ protected override void OnTextAlignChanged(EventArgs e) { - iRequestedContentAlignment = TextAlign; + iStringFormat = GetStringFormatFromContentAllignment(TextAlign); if (NeedToScroll()) { //Always align left when scrolling to avoid bugs - TextAlign = ContentAlignment.MiddleLeft; + iStringFormat.Alignment = StringAlignment.Near; } - iStringFormat = GetStringFormatFromContentAllignment(TextAlign); + Invalidate(); // base.OnTextAlignChanged(e);