Fixing string measurement issues. Font dialog now properly initialized with
loaded font.
1.1 --- a/MainForm.Designer.cs Tue Jul 08 21:49:30 2014 +0200
1.2 +++ b/MainForm.Designer.cs Wed Jul 09 11:06:46 2014 +0200
1.3 @@ -31,6 +31,7 @@
1.4 this.components = new System.ComponentModel.Container();
1.5 this.tabControl = new System.Windows.Forms.TabControl();
1.6 this.tabPageDisplay = new System.Windows.Forms.TabPage();
1.7 + this.checkBoxShowBorders = new System.Windows.Forms.CheckBox();
1.8 this.trackBarBrightness = new System.Windows.Forms.TrackBar();
1.9 this.buttonFill = new System.Windows.Forms.Button();
1.10 this.buttonClear = new System.Windows.Forms.Button();
1.11 @@ -38,6 +39,8 @@
1.12 this.buttonOpen = new System.Windows.Forms.Button();
1.13 this.buttonCapture = new System.Windows.Forms.Button();
1.14 this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
1.15 + this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.16 + this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.17 this.buttonFont = new System.Windows.Forms.Button();
1.18 this.tabPageTests = new System.Windows.Forms.TabPage();
1.19 this.fontDialog = new System.Windows.Forms.FontDialog();
1.20 @@ -46,9 +49,6 @@
1.21 this.toolStripStatusLabelConnect = new System.Windows.Forms.ToolStripStatusLabel();
1.22 this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel();
1.23 this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel();
1.24 - this.checkBoxShowBorders = new System.Windows.Forms.CheckBox();
1.25 - this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.26 - this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.27 this.tabControl.SuspendLayout();
1.28 this.tabPageDisplay.SuspendLayout();
1.29 ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
1.30 @@ -88,6 +88,17 @@
1.31 this.tabPageDisplay.Text = "Display";
1.32 this.tabPageDisplay.UseVisualStyleBackColor = true;
1.33 //
1.34 + // checkBoxShowBorders
1.35 + //
1.36 + this.checkBoxShowBorders.AutoSize = true;
1.37 + this.checkBoxShowBorders.Location = new System.Drawing.Point(113, 344);
1.38 + this.checkBoxShowBorders.Name = "checkBoxShowBorders";
1.39 + this.checkBoxShowBorders.Size = new System.Drawing.Size(91, 17);
1.40 + this.checkBoxShowBorders.TabIndex = 11;
1.41 + this.checkBoxShowBorders.Text = "Show borders";
1.42 + this.checkBoxShowBorders.UseVisualStyleBackColor = true;
1.43 + this.checkBoxShowBorders.CheckedChanged += new System.EventHandler(this.checkBoxShowBorders_CheckedChanged);
1.44 + //
1.45 // trackBarBrightness
1.46 //
1.47 this.trackBarBrightness.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
1.48 @@ -200,6 +211,39 @@
1.49 this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
1.50 this.tableLayoutPanel.TabIndex = 4;
1.51 //
1.52 + // marqueeLabelTop
1.53 + //
1.54 + this.marqueeLabelTop.AutoEllipsis = true;
1.55 + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.56 + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.57 + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
1.58 + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.59 + this.marqueeLabelTop.Name = "marqueeLabelTop";
1.60 + this.marqueeLabelTop.OwnTimer = false;
1.61 + this.marqueeLabelTop.PixelsPerSecond = 64;
1.62 + this.marqueeLabelTop.Separator = "|";
1.63 + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 30);
1.64 + this.marqueeLabelTop.TabIndex = 2;
1.65 + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.66 + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.67 + this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.68 + //
1.69 + // marqueeLabelBottom
1.70 + //
1.71 + this.marqueeLabelBottom.AutoEllipsis = true;
1.72 + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.73 + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 32);
1.74 + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.75 + this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.76 + this.marqueeLabelBottom.OwnTimer = false;
1.77 + this.marqueeLabelBottom.PixelsPerSecond = 64;
1.78 + this.marqueeLabelBottom.Separator = " | ";
1.79 + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31);
1.80 + this.marqueeLabelBottom.TabIndex = 3;
1.81 + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.82 + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.83 + this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.84 + //
1.85 // buttonFont
1.86 //
1.87 this.buttonFont.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
1.88 @@ -258,50 +302,6 @@
1.89 this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17);
1.90 this.toolStripStatusLabelFps.Text = "FPS";
1.91 //
1.92 - // checkBoxShowBorders
1.93 - //
1.94 - this.checkBoxShowBorders.AutoSize = true;
1.95 - this.checkBoxShowBorders.Location = new System.Drawing.Point(113, 344);
1.96 - this.checkBoxShowBorders.Name = "checkBoxShowBorders";
1.97 - this.checkBoxShowBorders.Size = new System.Drawing.Size(91, 17);
1.98 - this.checkBoxShowBorders.TabIndex = 11;
1.99 - this.checkBoxShowBorders.Text = "Show borders";
1.100 - this.checkBoxShowBorders.UseVisualStyleBackColor = true;
1.101 - this.checkBoxShowBorders.CheckedChanged += new System.EventHandler(this.checkBoxShowBorders_CheckedChanged);
1.102 - //
1.103 - // marqueeLabelTop
1.104 - //
1.105 - this.marqueeLabelTop.AutoEllipsis = true;
1.106 - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.107 - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.108 - this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
1.109 - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.110 - this.marqueeLabelTop.Name = "marqueeLabelTop";
1.111 - this.marqueeLabelTop.OwnTimer = false;
1.112 - this.marqueeLabelTop.PixelsPerSecond = 64;
1.113 - this.marqueeLabelTop.Separator = "";
1.114 - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 9);
1.115 - this.marqueeLabelTop.TabIndex = 2;
1.116 - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.117 - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.118 - this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.119 - //
1.120 - // marqueeLabelBottom
1.121 - //
1.122 - this.marqueeLabelBottom.AutoEllipsis = true;
1.123 - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.124 - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 21);
1.125 - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.126 - this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.127 - this.marqueeLabelBottom.OwnTimer = false;
1.128 - this.marqueeLabelBottom.PixelsPerSecond = 64;
1.129 - this.marqueeLabelBottom.Separator = null;
1.130 - this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
1.131 - this.marqueeLabelBottom.TabIndex = 3;
1.132 - this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.133 - this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.134 - this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.135 - //
1.136 // MainForm
1.137 //
1.138 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
2.1 --- a/MainForm.cs Tue Jul 08 21:49:30 2014 +0200
2.2 +++ b/MainForm.cs Wed Jul 09 11:06:46 2014 +0200
2.3 @@ -34,6 +34,7 @@
2.4 //fontDialog.ShowColor = true;
2.5 //fontDialog.ShowApply = true;
2.6 fontDialog.ShowEffects = true;
2.7 + fontDialog.Font = marqueeLabelTop.Font;
2.8 //fontDialog.ShowHelp = true;
2.9
2.10 //fontDlg.MaxSize = 40;
2.11 @@ -156,7 +157,7 @@
2.12 buttonClose.Enabled = true;
2.13 trackBarBrightness.Enabled = true;
2.14 trackBarBrightness.Minimum = iDisplay.MinBrightness();
2.15 - trackBarBrightness.Maximum = iDisplay.MaxBrightness();
2.16 + trackBarBrightness.Maximum = iDisplay.MaxBrightness();
2.17 trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
2.18 trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
2.19 trackBarBrightness.SmallChange = 1;
3.1 --- a/MarqueeLabel.cs Tue Jul 08 21:49:30 2014 +0200
3.2 +++ b/MarqueeLabel.cs Wed Jul 09 11:06:46 2014 +0200
3.3 @@ -23,18 +23,21 @@
3.4 [Description("Separator in our scrolling loop.")]
3.5 [DefaultValue(" | ")]
3.6 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
3.7 + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
3.8 public string Separator { get; set; }
3.9
3.10 [Category("Behavior")]
3.11 [Description("How fast is our text scrolling, in pixels per second.")]
3.12 [DefaultValue(32)]
3.13 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
3.14 + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
3.15 public int PixelsPerSecond { get; set; }
3.16
3.17 [Category("Behavior")]
3.18 [Description("Use an internal or an external timer.")]
3.19 [DefaultValue(true)]
3.20 [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
3.21 + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
3.22 public bool OwnTimer
3.23 {
3.24 get
3.25 @@ -139,6 +142,7 @@
3.26 private StringFormat GetStringFormatFromContentAllignment(ContentAlignment ca)
3.27 {
3.28 StringFormat format = new StringFormat();
3.29 + format = StringFormat.GenericTypographic;
3.30 switch (ca)
3.31 {
3.32 case ContentAlignment.TopCenter:
3.33 @@ -181,6 +185,7 @@
3.34
3.35 format.FormatFlags |= StringFormatFlags.NoWrap;
3.36 format.FormatFlags |= StringFormatFlags.NoClip;
3.37 + format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
3.38 format.Trimming = StringTrimming.None;
3.39
3.40 return format;
3.41 @@ -197,12 +202,14 @@
3.42
3.43 private void HandleTextSizeChange()
3.44 {
3.45 + //For all string measurements and drawing issues refer to the following article:
3.46 + // http://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number
3.47 //Update text size according to text and font
3.48 Graphics g = this.CreateGraphics();
3.49 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
3.50 - iTextSize = g.MeasureString(Text, Font);
3.51 - iSeparatorSize = g.MeasureString(Separator, Font);
3.52 iStringFormat = GetStringFormatFromContentAllignment(TextAlign);
3.53 + iTextSize = g.MeasureString(Text, Font, Int32.MaxValue, iStringFormat);
3.54 + iSeparatorSize = g.MeasureString(Separator, Font, Int32.MaxValue, iStringFormat);
3.55
3.56 if (NeedToScroll())
3.57 {