# HG changeset patch # User sl # Date 1404896806 -7200 # Node ID de55741d90f0fda6cb5974a98ffb18c708880245 # Parent 54671755add3f314467f92ff164f1c0e8f213355 Fixing string measurement issues. Font dialog now properly initialized with loaded font. diff -r 54671755add3 -r de55741d90f0 MainForm.Designer.cs --- a/MainForm.Designer.cs Tue Jul 08 21:49:30 2014 +0200 +++ b/MainForm.Designer.cs Wed Jul 09 11:06:46 2014 +0200 @@ -31,6 +31,7 @@ this.components = new System.ComponentModel.Container(); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPageDisplay = new System.Windows.Forms.TabPage(); + this.checkBoxShowBorders = new System.Windows.Forms.CheckBox(); this.trackBarBrightness = new System.Windows.Forms.TrackBar(); this.buttonFill = new System.Windows.Forms.Button(); this.buttonClear = new System.Windows.Forms.Button(); @@ -38,6 +39,8 @@ this.buttonOpen = new System.Windows.Forms.Button(); this.buttonCapture = new System.Windows.Forms.Button(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.buttonFont = new System.Windows.Forms.Button(); this.tabPageTests = new System.Windows.Forms.TabPage(); this.fontDialog = new System.Windows.Forms.FontDialog(); @@ -46,9 +49,6 @@ this.toolStripStatusLabelConnect = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel(); - this.checkBoxShowBorders = new System.Windows.Forms.CheckBox(); - this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); - this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.tabControl.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit(); @@ -88,6 +88,17 @@ this.tabPageDisplay.Text = "Display"; this.tabPageDisplay.UseVisualStyleBackColor = true; // + // checkBoxShowBorders + // + this.checkBoxShowBorders.AutoSize = true; + this.checkBoxShowBorders.Location = new System.Drawing.Point(113, 344); + this.checkBoxShowBorders.Name = "checkBoxShowBorders"; + this.checkBoxShowBorders.Size = new System.Drawing.Size(91, 17); + this.checkBoxShowBorders.TabIndex = 11; + this.checkBoxShowBorders.Text = "Show borders"; + this.checkBoxShowBorders.UseVisualStyleBackColor = true; + this.checkBoxShowBorders.CheckedChanged += new System.EventHandler(this.checkBoxShowBorders_CheckedChanged); + // // trackBarBrightness // this.trackBarBrightness.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -200,6 +211,39 @@ this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 4; // + // 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; + // // buttonFont // this.buttonFont.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -258,50 +302,6 @@ this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17); this.toolStripStatusLabelFps.Text = "FPS"; // - // checkBoxShowBorders - // - this.checkBoxShowBorders.AutoSize = true; - this.checkBoxShowBorders.Location = new System.Drawing.Point(113, 344); - this.checkBoxShowBorders.Name = "checkBoxShowBorders"; - this.checkBoxShowBorders.Size = new System.Drawing.Size(91, 17); - this.checkBoxShowBorders.TabIndex = 11; - this.checkBoxShowBorders.Text = "Show borders"; - this.checkBoxShowBorders.UseVisualStyleBackColor = true; - this.checkBoxShowBorders.CheckedChanged += new System.EventHandler(this.checkBoxShowBorders_CheckedChanged); - // - // 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, 9); - 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, 21); - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelBottom.Name = "marqueeLabelBottom"; - this.marqueeLabelBottom.OwnTimer = false; - this.marqueeLabelBottom.PixelsPerSecond = 64; - this.marqueeLabelBottom.Separator = null; - 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); diff -r 54671755add3 -r de55741d90f0 MainForm.cs --- a/MainForm.cs Tue Jul 08 21:49:30 2014 +0200 +++ b/MainForm.cs Wed Jul 09 11:06:46 2014 +0200 @@ -34,6 +34,7 @@ //fontDialog.ShowColor = true; //fontDialog.ShowApply = true; fontDialog.ShowEffects = true; + fontDialog.Font = marqueeLabelTop.Font; //fontDialog.ShowHelp = true; //fontDlg.MaxSize = 40; @@ -156,7 +157,7 @@ buttonClose.Enabled = true; trackBarBrightness.Enabled = true; trackBarBrightness.Minimum = iDisplay.MinBrightness(); - trackBarBrightness.Maximum = iDisplay.MaxBrightness(); + trackBarBrightness.Maximum = iDisplay.MaxBrightness(); trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness; trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5); trackBarBrightness.SmallChange = 1; diff -r 54671755add3 -r de55741d90f0 MarqueeLabel.cs --- a/MarqueeLabel.cs Tue Jul 08 21:49:30 2014 +0200 +++ b/MarqueeLabel.cs Wed Jul 09 11:06:46 2014 +0200 @@ -23,18 +23,21 @@ [Description("Separator in our scrolling loop.")] [DefaultValue(" | ")] [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public string Separator { get; set; } [Category("Behavior")] [Description("How fast is our text scrolling, in pixels per second.")] [DefaultValue(32)] [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public int PixelsPerSecond { get; set; } [Category("Behavior")] [Description("Use an internal or an external timer.")] [DefaultValue(true)] [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public bool OwnTimer { get @@ -139,6 +142,7 @@ private StringFormat GetStringFormatFromContentAllignment(ContentAlignment ca) { StringFormat format = new StringFormat(); + format = StringFormat.GenericTypographic; switch (ca) { case ContentAlignment.TopCenter: @@ -181,6 +185,7 @@ format.FormatFlags |= StringFormatFlags.NoWrap; format.FormatFlags |= StringFormatFlags.NoClip; + format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; format.Trimming = StringTrimming.None; return format; @@ -197,12 +202,14 @@ private void HandleTextSizeChange() { + //For all string measurements and drawing issues refer to the following article: + // http://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number //Update text size according to text and font Graphics g = this.CreateGraphics(); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; - iTextSize = g.MeasureString(Text, Font); - iSeparatorSize = g.MeasureString(Separator, Font); iStringFormat = GetStringFormatFromContentAllignment(TextAlign); + iTextSize = g.MeasureString(Text, Font, Int32.MaxValue, iStringFormat); + iSeparatorSize = g.MeasureString(Separator, Font, Int32.MaxValue, iStringFormat); if (NeedToScroll()) {