Now that we fixed that nasty iStringFormat static bug we could cleanup and
authorsl
Fri, 22 Aug 2014 10:55:34 +0200
changeset 42a9048f350975
parent 41 1864e4fd1728
child 43 86aad774b532
Now that we fixed that nasty iStringFormat static bug we could cleanup and
simplify our alginment code.
Server/MarqueeLabel.cs
     1.1 --- a/Server/MarqueeLabel.cs	Fri Aug 22 10:44:45 2014 +0200
     1.2 +++ b/Server/MarqueeLabel.cs	Fri Aug 22 10:55:34 2014 +0200
     1.3 @@ -20,7 +20,6 @@
     1.4          private SizeF iTextSize;
     1.5          private SizeF iSeparatorSize;
     1.6          private SizeF iScrollSize;
     1.7 -        private ContentAlignment iRequestedContentAlignment;
     1.8  
     1.9          [Category("Appearance")]
    1.10          [Description("Separator in our scrolling loop.")]
    1.11 @@ -84,7 +83,6 @@
    1.12              PixelsLeft = 0;
    1.13              CurrentPosition = 0;
    1.14              iBrush = new SolidBrush(ForeColor);
    1.15 -            iRequestedContentAlignment = TextAlign;
    1.16  
    1.17              //Following is needed if we ever switch from Label to Control base class.
    1.18              //Without it you get some pretty nasty flicker
    1.19 @@ -225,8 +223,6 @@
    1.20              CurrentPosition = 0;
    1.21              LastTickTime = DateTime.Now;
    1.22              PixelsLeft = 0;
    1.23 -            //Reset text align
    1.24 -            //TextAlign = iRequestedContentAlignment;
    1.25  
    1.26              //For all string measurements and drawing issues refer to the following article:
    1.27              // http://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number
    1.28 @@ -246,19 +242,9 @@
    1.29              if (NeedToScroll())
    1.30              {
    1.31                  //Always align left when scrolling
    1.32 -                //Somehow draw string still takes into our control alignment so we need to set it too
    1.33 -                //ContentAlignment original = TextAlign;
    1.34 -                TextAlign = ContentAlignment.MiddleLeft;
    1.35 -                //Make sure our original text alignment remain the same even though we override it when scrolling
    1.36 -                //iRequestedContentAlignment = original;
    1.37 -                //iStringFormat will get updated in OnTextAlignChanged
    1.38 -                //StringFormat.Alignment = StringAlignment.Near;
    1.39 +                iStringFormat.Alignment = StringAlignment.Near;
    1.40              }
    1.41 -            else
    1.42 -            {
    1.43 -                //We don't need to scroll so make sure the desired alignment is used
    1.44 -                TextAlign = iRequestedContentAlignment;
    1.45 -            }
    1.46 +
    1.47          }
    1.48  
    1.49          protected override void OnTextChanged(EventArgs e)
    1.50 @@ -277,13 +263,13 @@
    1.51  
    1.52          protected override void OnTextAlignChanged(EventArgs e)
    1.53          {
    1.54 -            iRequestedContentAlignment = TextAlign;
    1.55 +            iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
    1.56              if (NeedToScroll())
    1.57              {
    1.58                  //Always align left when scrolling to avoid bugs
    1.59 -                TextAlign = ContentAlignment.MiddleLeft;
    1.60 +                iStringFormat.Alignment = StringAlignment.Near;
    1.61              }
    1.62 -            iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
    1.63 +
    1.64              Invalidate();
    1.65              //
    1.66              base.OnTextAlignChanged(e);