Adding OwnTimer property to marquee. This enables us to use an external timer
and thus use a single timer for multiple marquee.
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Diagnostics;
7 using System.Threading.Tasks;
9 using System.Windows.Forms;
12 namespace SharpDisplayManager
14 class MarqueeLabel : Label
16 private bool iOwnTimer;
18 [Category("Behavior")]
19 [Description("How fast is our text scrolling, in pixels per second.")]
21 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
22 public int PixelsPerSecond { get; set; }
24 [Category("Behavior")]
25 [Description("Use an internal or an external timer.")]
27 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
42 Timer.Tick += new EventHandler(Timer_Tick);
55 private int CurrentPosition { get; set; }
56 private Timer Timer { get; set; }
57 private DateTime LastTickTime { get; set; }
58 private double PixelsLeft { get; set; }
59 //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00);
60 //DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
61 //Console.WriteLine(b.Subtract(a).TotalMinutes);
65 UseCompatibleTextRendering = true;
66 //PixelsPerSecond = 32;
67 LastTickTime = DateTime.Now;
71 public void UpdateAnimation(DateTime aLastTickTime, DateTime aNewTickTime)
73 while (CurrentPosition > Width)
75 CurrentPosition = -Width;
78 PixelsLeft += aNewTickTime.Subtract(aLastTickTime).TotalSeconds * PixelsPerSecond;
80 //Keep track of our pixels left over
81 //PixelsLeft = offset - Math.Truncate(offset);
82 double offset = Math.Truncate(PixelsLeft);
85 CurrentPosition += Convert.ToInt32(offset);
90 BackColor = Color.Red;
94 if (BackColor != Color.White)
96 BackColor = Color.White;
103 //BackColor = Color.Green;
106 //Only redraw if something has changed
113 void Timer_Tick(object sender, EventArgs e)
115 DateTime NewTickTime = DateTime.Now;
117 UpdateAnimation(LastTickTime, NewTickTime);
119 LastTickTime = NewTickTime;
122 protected override void OnPaint(PaintEventArgs e)
124 //Disable anti-aliasing
125 e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
126 e.Graphics.TranslateTransform((float)CurrentPosition, 0);
130 protected override void Dispose(bool disposing)