# HG changeset patch # User sl # Date 1408697085 -7200 # Node ID 1864e4fd172847a524c004a862115828844745d7 # Parent 4846aa0bb10c2858e6eb8969656cb9f5715912fa Adding buttons to test our alignment setup. Fixing a nasty bug in iStringFormat that would cause us to use the same instance in all marquee objects. diff -r 4846aa0bb10c -r 1864e4fd1728 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Fri Aug 22 08:24:51 2014 +0200 +++ b/Server/MainForm.Designer.cs Fri Aug 22 10:44:45 2014 +0200 @@ -31,6 +31,8 @@ this.components = new System.ComponentModel.Container(); this.panelDisplay = new System.Windows.Forms.Panel(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.fontDialog = new System.Windows.Forms.FontDialog(); this.timer = new System.Windows.Forms.Timer(this.components); this.statusStrip = new System.Windows.Forms.StatusStrip(); @@ -57,13 +59,14 @@ this.buttonFont = new System.Windows.Forms.Button(); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPageDesign = new System.Windows.Forms.TabPage(); + this.buttonAlignRight = new System.Windows.Forms.Button(); + this.buttonAlignCenter = new System.Windows.Forms.Button(); + this.buttonAlignLeft = new System.Windows.Forms.Button(); this.buttonRemoveColumn = new System.Windows.Forms.Button(); this.buttonAddColumn = new System.Windows.Forms.Button(); + this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); this.buttonRemoveRow = new System.Windows.Forms.Button(); this.buttonAddRow = new System.Windows.Forms.Button(); - this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); - this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); - this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); this.panelDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -160,6 +163,39 @@ this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 5; // + // marqueeLabelTop + // + this.marqueeLabelTop.AutoEllipsis = true; + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1); + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelTop.Name = "marqueeLabelTop"; + this.marqueeLabelTop.OwnTimer = false; + this.marqueeLabelTop.PixelsPerSecond = 64; + this.marqueeLabelTop.Separator = "|"; + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30); + this.marqueeLabelTop.TabIndex = 2; + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelTop.UseCompatibleTextRendering = true; + // + // marqueeLabelBottom + // + this.marqueeLabelBottom.AutoEllipsis = true; + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32); + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelBottom.Name = "marqueeLabelBottom"; + this.marqueeLabelBottom.OwnTimer = false; + this.marqueeLabelBottom.PixelsPerSecond = 64; + this.marqueeLabelBottom.Separator = "|"; + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31); + this.marqueeLabelBottom.TabIndex = 3; + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelBottom.UseCompatibleTextRendering = true; + // // timer // this.timer.Enabled = true; @@ -416,6 +452,9 @@ // // tabPageDesign // + this.tabPageDesign.Controls.Add(this.buttonAlignRight); + this.tabPageDesign.Controls.Add(this.buttonAlignCenter); + this.tabPageDesign.Controls.Add(this.buttonAlignLeft); this.tabPageDesign.Controls.Add(this.buttonRemoveColumn); this.tabPageDesign.Controls.Add(this.checkBoxFixedPitchFontOnly); this.tabPageDesign.Controls.Add(this.buttonAddColumn); @@ -432,6 +471,36 @@ this.tabPageDesign.Text = "Design"; this.tabPageDesign.UseVisualStyleBackColor = true; // + // buttonAlignRight + // + this.buttonAlignRight.Location = new System.Drawing.Point(171, 105); + this.buttonAlignRight.Name = "buttonAlignRight"; + this.buttonAlignRight.Size = new System.Drawing.Size(75, 23); + this.buttonAlignRight.TabIndex = 20; + this.buttonAlignRight.Text = "Align Right"; + this.buttonAlignRight.UseVisualStyleBackColor = true; + this.buttonAlignRight.Click += new System.EventHandler(this.buttonAlignRight_Click); + // + // buttonAlignCenter + // + this.buttonAlignCenter.Location = new System.Drawing.Point(89, 106); + this.buttonAlignCenter.Name = "buttonAlignCenter"; + this.buttonAlignCenter.Size = new System.Drawing.Size(75, 23); + this.buttonAlignCenter.TabIndex = 19; + this.buttonAlignCenter.Text = "Align Center"; + this.buttonAlignCenter.UseVisualStyleBackColor = true; + this.buttonAlignCenter.Click += new System.EventHandler(this.buttonAlignCenter_Click); + // + // buttonAlignLeft + // + this.buttonAlignLeft.Location = new System.Drawing.Point(7, 106); + this.buttonAlignLeft.Name = "buttonAlignLeft"; + this.buttonAlignLeft.Size = new System.Drawing.Size(75, 23); + this.buttonAlignLeft.TabIndex = 18; + this.buttonAlignLeft.Text = "Align Left"; + this.buttonAlignLeft.UseVisualStyleBackColor = true; + this.buttonAlignLeft.Click += new System.EventHandler(this.buttonAlignLeft_Click); + // // buttonRemoveColumn // this.buttonRemoveColumn.Location = new System.Drawing.Point(89, 37); @@ -452,6 +521,18 @@ this.buttonAddColumn.UseVisualStyleBackColor = true; this.buttonAddColumn.Click += new System.EventHandler(this.buttonAddColumn_Click); // + // checkBoxReverseScreen + // + this.checkBoxReverseScreen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.checkBoxReverseScreen.AutoSize = true; + this.checkBoxReverseScreen.Location = new System.Drawing.Point(485, 6); + this.checkBoxReverseScreen.Name = "checkBoxReverseScreen"; + this.checkBoxReverseScreen.Size = new System.Drawing.Size(101, 17); + this.checkBoxReverseScreen.TabIndex = 14; + this.checkBoxReverseScreen.Text = "Reverse screen"; + this.checkBoxReverseScreen.UseVisualStyleBackColor = true; + this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged); + // // buttonRemoveRow // this.buttonRemoveRow.Location = new System.Drawing.Point(7, 37); @@ -472,51 +553,6 @@ this.buttonAddRow.UseVisualStyleBackColor = true; this.buttonAddRow.Click += new System.EventHandler(this.buttonAddRow_Click); // - // marqueeLabelTop - // - this.marqueeLabelTop.AutoEllipsis = true; - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelTop.Location = new System.Drawing.Point(1, -9); - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelTop.Name = "marqueeLabelTop"; - this.marqueeLabelTop.OwnTimer = false; - this.marqueeLabelTop.PixelsPerSecond = 64; - this.marqueeLabelTop.Separator = "|"; - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 1); - this.marqueeLabelTop.TabIndex = 2; - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabelTop.UseCompatibleTextRendering = true; - // - // marqueeLabelBottom - // - this.marqueeLabelBottom.AutoEllipsis = true; - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 2); - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelBottom.Name = "marqueeLabelBottom"; - this.marqueeLabelBottom.OwnTimer = false; - this.marqueeLabelBottom.PixelsPerSecond = 64; - this.marqueeLabelBottom.Separator = "|"; - 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; - // - // checkBoxReverseScreen - // - this.checkBoxReverseScreen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.checkBoxReverseScreen.AutoSize = true; - this.checkBoxReverseScreen.Location = new System.Drawing.Point(485, 6); - this.checkBoxReverseScreen.Name = "checkBoxReverseScreen"; - this.checkBoxReverseScreen.Size = new System.Drawing.Size(101, 17); - this.checkBoxReverseScreen.TabIndex = 14; - this.checkBoxReverseScreen.Text = "Reverse screen"; - this.checkBoxReverseScreen.UseVisualStyleBackColor = true; - this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -585,6 +621,9 @@ private System.Windows.Forms.Button buttonRemoveRow; private System.Windows.Forms.Button buttonAddRow; private System.Windows.Forms.CheckBox checkBoxReverseScreen; + private System.Windows.Forms.Button buttonAlignRight; + private System.Windows.Forms.Button buttonAlignCenter; + private System.Windows.Forms.Button buttonAlignLeft; } } diff -r 4846aa0bb10c -r 1864e4fd1728 Server/MainForm.cs --- a/Server/MainForm.cs Fri Aug 22 08:24:51 2014 +0200 +++ b/Server/MainForm.cs Fri Aug 22 10:44:45 2014 +0200 @@ -760,6 +760,23 @@ } } + private void buttonAlignLeft_Click(object sender, EventArgs e) + { + marqueeLabelTop.TextAlign = ContentAlignment.MiddleLeft; + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleLeft; + } + + private void buttonAlignCenter_Click(object sender, EventArgs e) + { + marqueeLabelTop.TextAlign = ContentAlignment.MiddleCenter; + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleCenter; + } + + private void buttonAlignRight_Click(object sender, EventArgs e) + { + marqueeLabelTop.TextAlign = ContentAlignment.MiddleRight; + marqueeLabelBottom.TextAlign = ContentAlignment.MiddleRight; + } } diff -r 4846aa0bb10c -r 1864e4fd1728 Server/MarqueeLabel.cs --- a/Server/MarqueeLabel.cs Fri Aug 22 08:24:51 2014 +0200 +++ b/Server/MarqueeLabel.cs Fri Aug 22 10:44:45 2014 +0200 @@ -20,7 +20,7 @@ private SizeF iTextSize; private SizeF iSeparatorSize; private SizeF iScrollSize; - //private ContentAlignment iRequestedContentAlignment; + private ContentAlignment iRequestedContentAlignment; [Category("Appearance")] [Description("Separator in our scrolling loop.")] @@ -84,13 +84,13 @@ PixelsLeft = 0; CurrentPosition = 0; iBrush = new SolidBrush(ForeColor); - //iRequestedContentAlignment = TextAlign; + iRequestedContentAlignment = TextAlign; - //Following is needed if we ever switch from Label to Control base class. + //Following is needed if we ever switch from Label to Control base class. //Without it you get some pretty nasty flicker //SetStyle(ControlStyles.OptimizedDoubleBuffer, true); //SetStyle(ControlStyles.UserPaint, true); - //SetStyle(ControlStyles.AllPaintingInWmPaint, true); + //SetStyle(ControlStyles.AllPaintingInWmPaint, true); //SetStyle(ControlStyles.DoubleBuffer, true); } @@ -161,8 +161,7 @@ private StringFormat GetStringFormatFromContentAllignment(ContentAlignment ca) { - StringFormat format = new StringFormat(); - format = StringFormat.GenericTypographic; + StringFormat format = new StringFormat(StringFormat.GenericTypographic); switch (ca) { case ContentAlignment.TopCenter: @@ -251,9 +250,14 @@ //ContentAlignment original = TextAlign; TextAlign = ContentAlignment.MiddleLeft; //Make sure our original text alignment remain the same even though we override it when scrolling - //iRequestedContentAlignment = original; + //iRequestedContentAlignment = original; //iStringFormat will get updated in OnTextAlignChanged - //iStringFormat.Alignment = StringAlignment.Near; + //StringFormat.Alignment = StringAlignment.Near; + } + else + { + //We don't need to scroll so make sure the desired alignment is used + TextAlign = iRequestedContentAlignment; } } @@ -273,10 +277,16 @@ protected override void OnTextAlignChanged(EventArgs e) { + iRequestedContentAlignment = TextAlign; + if (NeedToScroll()) + { + //Always align left when scrolling to avoid bugs + TextAlign = ContentAlignment.MiddleLeft; + } iStringFormat = GetStringFormatFromContentAllignment(TextAlign); - //iRequestedContentAlignment = TextAlign; + Invalidate(); + // base.OnTextAlignChanged(e); - } protected override void OnPaint(PaintEventArgs e) @@ -287,7 +297,7 @@ { //Draw it all in a single call would take kerning into account //e.Graphics.TranslateTransform(-(float)CurrentPosition, 0); - //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, iStringFormat); + //e.Graphics.DrawString(Text + Separator + Text, Font, iBrush, ClientRectangle, StringFormat); //Doing separate draw operation allows us not to take kerning into account between separator and string //Draw the first one