Server/MarqueeLabel.cs
changeset 41 1864e4fd1728
parent 35 f3893924a6eb
child 42 a9048f350975
     1.1 --- a/Server/MarqueeLabel.cs	Fri Aug 22 08:24:51 2014 +0200
     1.2 +++ b/Server/MarqueeLabel.cs	Fri Aug 22 10:44:45 2014 +0200
     1.3 @@ -20,7 +20,7 @@
     1.4          private SizeF iTextSize;
     1.5          private SizeF iSeparatorSize;
     1.6          private SizeF iScrollSize;
     1.7 -        //private ContentAlignment iRequestedContentAlignment;
     1.8 +        private ContentAlignment iRequestedContentAlignment;
     1.9  
    1.10          [Category("Appearance")]
    1.11          [Description("Separator in our scrolling loop.")]
    1.12 @@ -84,13 +84,13 @@
    1.13              PixelsLeft = 0;
    1.14              CurrentPosition = 0;
    1.15              iBrush = new SolidBrush(ForeColor);
    1.16 -            //iRequestedContentAlignment = TextAlign;
    1.17 +            iRequestedContentAlignment = TextAlign;
    1.18  
    1.19 -            //Following is needed if we ever switch from Label to Control base class. 
    1.20 +            //Following is needed if we ever switch from Label to Control base class.
    1.21              //Without it you get some pretty nasty flicker
    1.22              //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    1.23              //SetStyle(ControlStyles.UserPaint, true);
    1.24 -            //SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
    1.25 +            //SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    1.26              //SetStyle(ControlStyles.DoubleBuffer, true);
    1.27          }
    1.28  
    1.29 @@ -161,8 +161,7 @@
    1.30  
    1.31          private StringFormat GetStringFormatFromContentAllignment(ContentAlignment ca)
    1.32          {
    1.33 -            StringFormat format = new StringFormat();
    1.34 -            format = StringFormat.GenericTypographic;
    1.35 +            StringFormat format = new StringFormat(StringFormat.GenericTypographic);
    1.36              switch (ca)
    1.37              {
    1.38                  case ContentAlignment.TopCenter:
    1.39 @@ -251,9 +250,14 @@
    1.40                  //ContentAlignment original = TextAlign;
    1.41                  TextAlign = ContentAlignment.MiddleLeft;
    1.42                  //Make sure our original text alignment remain the same even though we override it when scrolling
    1.43 -                //iRequestedContentAlignment = original; 
    1.44 +                //iRequestedContentAlignment = original;
    1.45                  //iStringFormat will get updated in OnTextAlignChanged
    1.46 -                //iStringFormat.Alignment = StringAlignment.Near;
    1.47 +                //StringFormat.Alignment = StringAlignment.Near;
    1.48 +            }
    1.49 +            else
    1.50 +            {
    1.51 +                //We don't need to scroll so make sure the desired alignment is used
    1.52 +                TextAlign = iRequestedContentAlignment;
    1.53              }
    1.54          }
    1.55  
    1.56 @@ -273,10 +277,16 @@
    1.57  
    1.58          protected override void OnTextAlignChanged(EventArgs e)
    1.59          {
    1.60 +            iRequestedContentAlignment = TextAlign;
    1.61 +            if (NeedToScroll())
    1.62 +            {
    1.63 +                //Always align left when scrolling to avoid bugs
    1.64 +                TextAlign = ContentAlignment.MiddleLeft;
    1.65 +            }
    1.66              iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
    1.67 -            //iRequestedContentAlignment = TextAlign;
    1.68 +            Invalidate();
    1.69 +            //
    1.70              base.OnTextAlignChanged(e);
    1.71 -
    1.72          }
    1.73  
    1.74          protected override void OnPaint(PaintEventArgs e)
    1.75 @@ -287,7 +297,7 @@
    1.76              {
    1.77                  //Draw it all in a single call would take kerning into account
    1.78                  //e.Graphics.TranslateTransform(-(float)CurrentPosition, 0);
    1.79 -                //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, iStringFormat);
    1.80 +                //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, StringFormat);
    1.81  
    1.82                  //Doing separate draw operation allows us not to take kerning into account between separator and string
    1.83                  //Draw the first one