Adding OwnTimer property to marquee. This enables us to use an external timer
and thus use a single timer for multiple marquee.
1.1 --- a/MainForm.Designer.cs Sat Jun 14 15:05:04 2014 +0200
1.2 +++ b/MainForm.Designer.cs Mon Jun 16 12:18:46 2014 +0200
1.3 @@ -28,16 +28,17 @@
1.4 /// </summary>
1.5 private void InitializeComponent()
1.6 {
1.7 + this.components = new System.ComponentModel.Container();
1.8 this.tabControl = new System.Windows.Forms.TabControl();
1.9 this.tabPageDisplay = new System.Windows.Forms.TabPage();
1.10 this.buttonCapture = new System.Windows.Forms.Button();
1.11 this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
1.12 - this.marqueeLabel1 = new SharpDisplayManager.MarqueeLabel();
1.13 - this.marqueeLabel2 = new SharpDisplayManager.MarqueeLabel();
1.14 this.buttonFont = new System.Windows.Forms.Button();
1.15 this.tabPageTests = new System.Windows.Forms.TabPage();
1.16 this.fontDialog = new System.Windows.Forms.FontDialog();
1.17 - this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
1.18 + this.timer = new System.Windows.Forms.Timer(this.components);
1.19 + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.20 + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.21 this.tabControl.SuspendLayout();
1.22 this.tabPageDisplay.SuspendLayout();
1.23 this.tableLayoutPanel.SuspendLayout();
1.24 @@ -84,8 +85,8 @@
1.25 this.tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
1.26 this.tableLayoutPanel.ColumnCount = 1;
1.27 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
1.28 - this.tableLayoutPanel.Controls.Add(this.marqueeLabel1, 0, 0);
1.29 - this.tableLayoutPanel.Controls.Add(this.marqueeLabel2, 0, 1);
1.30 + this.tableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0);
1.31 + this.tableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1);
1.32 this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165);
1.33 this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
1.34 this.tableLayoutPanel.Name = "tableLayoutPanel";
1.35 @@ -96,36 +97,17 @@
1.36 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.37 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.38 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.39 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.40 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.41 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.42 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.43 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.44 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.45 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.46 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.47 this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
1.48 this.tableLayoutPanel.TabIndex = 4;
1.49 //
1.50 - // marqueeLabel1
1.51 - //
1.52 - this.marqueeLabel1.BackColor = System.Drawing.Color.Transparent;
1.53 - this.marqueeLabel1.Dock = System.Windows.Forms.DockStyle.Fill;
1.54 - this.marqueeLabel1.Location = new System.Drawing.Point(1, 1);
1.55 - this.marqueeLabel1.Margin = new System.Windows.Forms.Padding(0);
1.56 - this.marqueeLabel1.Name = "marqueeLabel1";
1.57 - this.marqueeLabel1.PixelsPerSecond = 128;
1.58 - this.marqueeLabel1.Size = new System.Drawing.Size(254, 30);
1.59 - this.marqueeLabel1.TabIndex = 2;
1.60 - this.marqueeLabel1.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.61 - this.marqueeLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.62 - this.marqueeLabel1.UseCompatibleTextRendering = true;
1.63 - //
1.64 - // marqueeLabel2
1.65 - //
1.66 - this.marqueeLabel2.Dock = System.Windows.Forms.DockStyle.Fill;
1.67 - this.marqueeLabel2.Location = new System.Drawing.Point(1, 32);
1.68 - this.marqueeLabel2.Margin = new System.Windows.Forms.Padding(0);
1.69 - this.marqueeLabel2.Name = "marqueeLabel2";
1.70 - this.marqueeLabel2.PixelsPerSecond = 64;
1.71 - this.marqueeLabel2.Size = new System.Drawing.Size(254, 31);
1.72 - this.marqueeLabel2.TabIndex = 3;
1.73 - this.marqueeLabel2.Text = "abcdefghijklmnopqrst-0123456789";
1.74 - this.marqueeLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.75 - this.marqueeLabel2.UseCompatibleTextRendering = true;
1.76 - //
1.77 // buttonFont
1.78 //
1.79 this.buttonFont.Location = new System.Drawing.Point(6, 307);
1.80 @@ -146,6 +128,41 @@
1.81 this.tabPageTests.Text = "Test";
1.82 this.tabPageTests.UseVisualStyleBackColor = true;
1.83 //
1.84 + // timer
1.85 + //
1.86 + this.timer.Enabled = true;
1.87 + this.timer.Interval = 50;
1.88 + this.timer.Tick += new System.EventHandler(this.timer_Tick);
1.89 + //
1.90 + // marqueeLabelTop
1.91 + //
1.92 + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.93 + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.94 + this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187);
1.95 + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.96 + this.marqueeLabelTop.Name = "marqueeLabelTop";
1.97 + this.marqueeLabelTop.OwnTimer = false;
1.98 + this.marqueeLabelTop.PixelsPerSecond = 64;
1.99 + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20);
1.100 + this.marqueeLabelTop.TabIndex = 2;
1.101 + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.102 + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.103 + this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.104 + //
1.105 + // marqueeLabelBottom
1.106 + //
1.107 + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.108 + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61);
1.109 + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.110 + this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.111 + this.marqueeLabelBottom.OwnTimer = false;
1.112 + this.marqueeLabelBottom.PixelsPerSecond = 64;
1.113 + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
1.114 + this.marqueeLabelBottom.TabIndex = 3;
1.115 + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.116 + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.117 + this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.118 + //
1.119 // MainForm
1.120 //
1.121 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.122 @@ -168,11 +185,11 @@
1.123 private System.Windows.Forms.TabPage tabPageTests;
1.124 private System.Windows.Forms.Button buttonFont;
1.125 private System.Windows.Forms.FontDialog fontDialog;
1.126 - private System.ComponentModel.BackgroundWorker backgroundWorker1;
1.127 private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
1.128 - private MarqueeLabel marqueeLabel1;
1.129 - private MarqueeLabel marqueeLabel2;
1.130 + private MarqueeLabel marqueeLabelTop;
1.131 + private MarqueeLabel marqueeLabelBottom;
1.132 private System.Windows.Forms.Button buttonCapture;
1.133 + private System.Windows.Forms.Timer timer;
1.134 }
1.135 }
1.136
2.1 --- a/MainForm.cs Sat Jun 14 15:05:04 2014 +0200
2.2 +++ b/MainForm.cs Mon Jun 16 12:18:46 2014 +0200
2.3 @@ -13,8 +13,12 @@
2.4 {
2.5 public partial class MainForm : Form
2.6 {
2.7 + DateTime LastTickTime;
2.8 +
2.9 public MainForm()
2.10 {
2.11 + LastTickTime = DateTime.Now;
2.12 +
2.13 InitializeComponent();
2.14 }
2.15
2.16 @@ -53,5 +57,16 @@
2.17 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
2.18 bmp.Save("c:\\capture.png");
2.19 }
2.20 +
2.21 + private void timer_Tick(object sender, EventArgs e)
2.22 + {
2.23 + //Update our animations
2.24 + DateTime NewTickTime = DateTime.Now;
2.25 +
2.26 + marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
2.27 + marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
2.28 +
2.29 + LastTickTime = NewTickTime;
2.30 + }
2.31 }
2.32 }
3.1 --- a/MainForm.resx Sat Jun 14 15:05:04 2014 +0200
3.2 +++ b/MainForm.resx Mon Jun 16 12:18:46 2014 +0200
3.3 @@ -120,7 +120,7 @@
3.4 <metadata name="fontDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.5 <value>17, 17</value>
3.6 </metadata>
3.7 - <metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.8 + <metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.9 <value>126, 17</value>
3.10 </metadata>
3.11 </root>
3.12 \ No newline at end of file
4.1 --- a/MarqueeLabel.cs Sat Jun 14 15:05:04 2014 +0200
4.2 +++ b/MarqueeLabel.cs Mon Jun 16 12:18:46 2014 +0200
4.3 @@ -13,9 +13,7 @@
4.4 {
4.5 class MarqueeLabel : Label
4.6 {
4.7 - private int CurrentPosition { get; set; }
4.8 - private Timer Timer { get; set; }
4.9 -
4.10 + private bool iOwnTimer;
4.11
4.12 [Category("Behavior")]
4.13 [Description("How fast is our text scrolling, in pixels per second.")]
4.14 @@ -23,35 +21,61 @@
4.15 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
4.16 public int PixelsPerSecond { get; set; }
4.17
4.18 + [Category("Behavior")]
4.19 + [Description("Use an internal or an external timer.")]
4.20 + [DefaultValue(true)]
4.21 + [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
4.22 + public bool OwnTimer
4.23 + {
4.24 + get
4.25 + {
4.26 + return iOwnTimer;
4.27 + }
4.28 + set
4.29 + {
4.30 + iOwnTimer = value;
4.31 +
4.32 + if (iOwnTimer)
4.33 + {
4.34 + Timer = new Timer();
4.35 + Timer.Interval = 10;
4.36 + Timer.Tick += new EventHandler(Timer_Tick);
4.37 + Timer.Start();
4.38 + }
4.39 + else
4.40 + {
4.41 + if (Timer != null)
4.42 + Timer.Dispose();
4.43 + Timer = null;
4.44 + }
4.45 +
4.46 + }
4.47 + }
4.48 +
4.49 + private int CurrentPosition { get; set; }
4.50 + private Timer Timer { get; set; }
4.51 private DateTime LastTickTime { get; set; }
4.52 private double PixelsLeft { get; set; }
4.53 //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00);
4.54 -//DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
4.55 -//Console.WriteLine(b.Subtract(a).TotalMinutes);
4.56 + //DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
4.57 + //Console.WriteLine(b.Subtract(a).TotalMinutes);
4.58
4.59 public MarqueeLabel()
4.60 {
4.61 UseCompatibleTextRendering = true;
4.62 - Timer = new Timer();
4.63 - Timer.Interval = 10;
4.64 - Timer.Tick += new EventHandler(Timer_Tick);
4.65 - Timer.Start();
4.66 //PixelsPerSecond = 32;
4.67 LastTickTime = DateTime.Now;
4.68 PixelsLeft = 0;
4.69 }
4.70
4.71 - void Timer_Tick(object sender, EventArgs e)
4.72 + public void UpdateAnimation(DateTime aLastTickTime, DateTime aNewTickTime)
4.73 {
4.74 while (CurrentPosition > Width)
4.75 {
4.76 CurrentPosition = -Width;
4.77 }
4.78
4.79 - DateTime NewTickTime=DateTime.Now;
4.80 - PixelsLeft += NewTickTime.Subtract(LastTickTime).TotalSeconds * PixelsPerSecond;
4.81 - LastTickTime = NewTickTime;
4.82 - //offset += PixelsLeft;
4.83 + PixelsLeft += aNewTickTime.Subtract(aLastTickTime).TotalSeconds * PixelsPerSecond;
4.84
4.85 //Keep track of our pixels left over
4.86 //PixelsLeft = offset - Math.Truncate(offset);
4.87 @@ -84,9 +108,15 @@
4.88 {
4.89 Invalidate();
4.90 }
4.91 + }
4.92
4.93 -
4.94 -
4.95 + void Timer_Tick(object sender, EventArgs e)
4.96 + {
4.97 + DateTime NewTickTime = DateTime.Now;
4.98 + //
4.99 + UpdateAnimation(LastTickTime, NewTickTime);
4.100 + //
4.101 + LastTickTime = NewTickTime;
4.102 }
4.103
4.104 protected override void OnPaint(PaintEventArgs e)