First contrib.
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 int CurrentPosition { get; set; }
17 private Timer Timer { get; set; }
20 [Category("Behavior")]
21 [Description("How fast is our text scrolling, in pixels per second.")]
23 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
24 public int PixelsPerSecond { get; set; }
26 private DateTime LastTickTime { get; set; }
27 private double PixelsLeft { get; set; }
28 //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00);
29 //DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
30 //Console.WriteLine(b.Subtract(a).TotalMinutes);
34 UseCompatibleTextRendering = true;
37 Timer.Tick += new EventHandler(Timer_Tick);
39 //PixelsPerSecond = 32;
40 LastTickTime = DateTime.Now;
44 void Timer_Tick(object sender, EventArgs e)
46 while (CurrentPosition > Width)
48 CurrentPosition = -Width;
51 DateTime NewTickTime=DateTime.Now;
52 PixelsLeft += NewTickTime.Subtract(LastTickTime).TotalSeconds * PixelsPerSecond;
53 LastTickTime = NewTickTime;
54 //offset += PixelsLeft;
56 //Keep track of our pixels left over
57 //PixelsLeft = offset - Math.Truncate(offset);
58 double offset = Math.Truncate(PixelsLeft);
61 CurrentPosition += Convert.ToInt32(offset);
66 BackColor = Color.Red;
70 if (BackColor != Color.White)
72 BackColor = Color.White;
79 //BackColor = Color.Green;
82 //Only redraw if something has changed
92 protected override void OnPaint(PaintEventArgs e)
94 //Disable anti-aliasing
95 e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
96 e.Graphics.TranslateTransform((float)CurrentPosition, 0);
100 protected override void Dispose(bool disposing)