# HG changeset patch # User sl # Date 1402913926 -7200 # Node ID f516c3f656bf021666bb80571aa2577bb04202a0 # Parent 9bf16f9b8f1f095e6c3d2d01c224af607e4d0718 Adding OwnTimer property to marquee. This enables us to use an external timer and thus use a single timer for multiple marquee. diff -r 9bf16f9b8f1f -r f516c3f656bf MainForm.Designer.cs --- a/MainForm.Designer.cs Sat Jun 14 15:05:04 2014 +0200 +++ b/MainForm.Designer.cs Mon Jun 16 12:18:46 2014 +0200 @@ -28,16 +28,17 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPageDisplay = new System.Windows.Forms.TabPage(); this.buttonCapture = new System.Windows.Forms.Button(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); - this.marqueeLabel1 = new SharpDisplayManager.MarqueeLabel(); - this.marqueeLabel2 = new SharpDisplayManager.MarqueeLabel(); this.buttonFont = new System.Windows.Forms.Button(); this.tabPageTests = new System.Windows.Forms.TabPage(); this.fontDialog = new System.Windows.Forms.FontDialog(); - this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.timer = new System.Windows.Forms.Timer(this.components); + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.tabControl.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); @@ -84,8 +85,8 @@ this.tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; this.tableLayoutPanel.ColumnCount = 1; this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel.Controls.Add(this.marqueeLabel1, 0, 0); - this.tableLayoutPanel.Controls.Add(this.marqueeLabel2, 0, 1); + this.tableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0); + this.tableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1); this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165); this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel.Name = "tableLayoutPanel"; @@ -96,36 +97,17 @@ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 4; // - // marqueeLabel1 - // - this.marqueeLabel1.BackColor = System.Drawing.Color.Transparent; - this.marqueeLabel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabel1.Location = new System.Drawing.Point(1, 1); - this.marqueeLabel1.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabel1.Name = "marqueeLabel1"; - this.marqueeLabel1.PixelsPerSecond = 128; - this.marqueeLabel1.Size = new System.Drawing.Size(254, 30); - this.marqueeLabel1.TabIndex = 2; - this.marqueeLabel1.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; - this.marqueeLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabel1.UseCompatibleTextRendering = true; - // - // marqueeLabel2 - // - this.marqueeLabel2.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabel2.Location = new System.Drawing.Point(1, 32); - this.marqueeLabel2.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabel2.Name = "marqueeLabel2"; - this.marqueeLabel2.PixelsPerSecond = 64; - this.marqueeLabel2.Size = new System.Drawing.Size(254, 31); - this.marqueeLabel2.TabIndex = 3; - this.marqueeLabel2.Text = "abcdefghijklmnopqrst-0123456789"; - this.marqueeLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabel2.UseCompatibleTextRendering = true; - // // buttonFont // this.buttonFont.Location = new System.Drawing.Point(6, 307); @@ -146,6 +128,41 @@ this.tabPageTests.Text = "Test"; this.tabPageTests.UseVisualStyleBackColor = true; // + // timer + // + this.timer.Enabled = true; + this.timer.Interval = 50; + this.timer.Tick += new System.EventHandler(this.timer_Tick); + // + // marqueeLabelTop + // + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187); + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelTop.Name = "marqueeLabelTop"; + this.marqueeLabelTop.OwnTimer = false; + this.marqueeLabelTop.PixelsPerSecond = 64; + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20); + this.marqueeLabelTop.TabIndex = 2; + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelTop.UseCompatibleTextRendering = true; + // + // marqueeLabelBottom + // + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61); + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelBottom.Name = "marqueeLabelBottom"; + this.marqueeLabelBottom.OwnTimer = false; + this.marqueeLabelBottom.PixelsPerSecond = 64; + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20); + this.marqueeLabelBottom.TabIndex = 3; + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelBottom.UseCompatibleTextRendering = true; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -168,11 +185,11 @@ private System.Windows.Forms.TabPage tabPageTests; private System.Windows.Forms.Button buttonFont; private System.Windows.Forms.FontDialog fontDialog; - private System.ComponentModel.BackgroundWorker backgroundWorker1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; - private MarqueeLabel marqueeLabel1; - private MarqueeLabel marqueeLabel2; + private MarqueeLabel marqueeLabelTop; + private MarqueeLabel marqueeLabelBottom; private System.Windows.Forms.Button buttonCapture; + private System.Windows.Forms.Timer timer; } } diff -r 9bf16f9b8f1f -r f516c3f656bf MainForm.cs --- a/MainForm.cs Sat Jun 14 15:05:04 2014 +0200 +++ b/MainForm.cs Mon Jun 16 12:18:46 2014 +0200 @@ -13,8 +13,12 @@ { public partial class MainForm : Form { + DateTime LastTickTime; + public MainForm() { + LastTickTime = DateTime.Now; + InitializeComponent(); } @@ -53,5 +57,16 @@ tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); bmp.Save("c:\\capture.png"); } + + private void timer_Tick(object sender, EventArgs e) + { + //Update our animations + DateTime NewTickTime = DateTime.Now; + + marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime); + marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime); + + LastTickTime = NewTickTime; + } } } diff -r 9bf16f9b8f1f -r f516c3f656bf MainForm.resx --- a/MainForm.resx Sat Jun 14 15:05:04 2014 +0200 +++ b/MainForm.resx Mon Jun 16 12:18:46 2014 +0200 @@ -120,7 +120,7 @@ 17, 17 - + 126, 17 \ No newline at end of file diff -r 9bf16f9b8f1f -r f516c3f656bf MarqueeLabel.cs --- a/MarqueeLabel.cs Sat Jun 14 15:05:04 2014 +0200 +++ b/MarqueeLabel.cs Mon Jun 16 12:18:46 2014 +0200 @@ -13,9 +13,7 @@ { class MarqueeLabel : Label { - private int CurrentPosition { get; set; } - private Timer Timer { get; set; } - + private bool iOwnTimer; [Category("Behavior")] [Description("How fast is our text scrolling, in pixels per second.")] @@ -23,35 +21,61 @@ [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] public int PixelsPerSecond { get; set; } + [Category("Behavior")] + [Description("Use an internal or an external timer.")] + [DefaultValue(true)] + [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] + public bool OwnTimer + { + get + { + return iOwnTimer; + } + set + { + iOwnTimer = value; + + if (iOwnTimer) + { + Timer = new Timer(); + Timer.Interval = 10; + Timer.Tick += new EventHandler(Timer_Tick); + Timer.Start(); + } + else + { + if (Timer != null) + Timer.Dispose(); + Timer = null; + } + + } + } + + private int CurrentPosition { get; set; } + private Timer Timer { get; set; } private DateTime LastTickTime { get; set; } private double PixelsLeft { get; set; } //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00); -//DateTime b = new DateTime(2010, 05, 12, 13, 45, 00); -//Console.WriteLine(b.Subtract(a).TotalMinutes); + //DateTime b = new DateTime(2010, 05, 12, 13, 45, 00); + //Console.WriteLine(b.Subtract(a).TotalMinutes); public MarqueeLabel() { UseCompatibleTextRendering = true; - Timer = new Timer(); - Timer.Interval = 10; - Timer.Tick += new EventHandler(Timer_Tick); - Timer.Start(); //PixelsPerSecond = 32; LastTickTime = DateTime.Now; PixelsLeft = 0; } - void Timer_Tick(object sender, EventArgs e) + public void UpdateAnimation(DateTime aLastTickTime, DateTime aNewTickTime) { while (CurrentPosition > Width) { CurrentPosition = -Width; } - DateTime NewTickTime=DateTime.Now; - PixelsLeft += NewTickTime.Subtract(LastTickTime).TotalSeconds * PixelsPerSecond; - LastTickTime = NewTickTime; - //offset += PixelsLeft; + PixelsLeft += aNewTickTime.Subtract(aLastTickTime).TotalSeconds * PixelsPerSecond; //Keep track of our pixels left over //PixelsLeft = offset - Math.Truncate(offset); @@ -84,9 +108,15 @@ { Invalidate(); } + } - - + void Timer_Tick(object sender, EventArgs e) + { + DateTime NewTickTime = DateTime.Now; + // + UpdateAnimation(LastTickTime, NewTickTime); + // + LastTickTime = NewTickTime; } protected override void OnPaint(PaintEventArgs e)