Server/MainForm.cs
changeset 60 4f2a73683adc
parent 59 9979787100b1
child 61 5a24e79384be
     1.1 --- a/Server/MainForm.cs	Mon Sep 22 10:05:45 2014 +0200
     1.2 +++ b/Server/MainForm.cs	Mon Sep 22 13:00:27 2014 +0200
     1.3 @@ -99,7 +99,8 @@
     1.4              //fontDialog.ShowColor = true;
     1.5              //fontDialog.ShowApply = true;
     1.6              fontDialog.ShowEffects = true;
     1.7 -            fontDialog.Font = marqueeLabelTop.Font;
     1.8 +            MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[0];
     1.9 +            fontDialog.Font = label.Font;
    1.10  
    1.11              fontDialog.FixedPitchOnly = checkBoxFixedPitchFontOnly.Checked;
    1.12  
    1.13 @@ -120,8 +121,10 @@
    1.14                  //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
    1.15  
    1.16                  //MessageBox.Show("Ok");
    1.17 -                marqueeLabelTop.Font = fontDialog.Font;
    1.18 -                marqueeLabelBottom.Font = fontDialog.Font;
    1.19 +                foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
    1.20 +                {
    1.21 +                    ctrl.Font = fontDialog.Font;
    1.22 +                }
    1.23                  cds.Font = fontDialog.Font;
    1.24                  Properties.Settings.Default.Save();
    1.25                  //
    1.26 @@ -148,9 +151,10 @@
    1.27              }
    1.28  
    1.29              //Now check font height and show a warning if needed.
    1.30 -            if (marqueeLabelBottom.Font.Height > marqueeLabelBottom.Height)
    1.31 +            MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[0];
    1.32 +            if (label.Font.Height > label.Height)
    1.33              {
    1.34 -                labelWarning.Text = "WARNING: Selected font is too height by " + (marqueeLabelBottom.Font.Height - marqueeLabelBottom.Height) + " pixels!";
    1.35 +                labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!";
    1.36                  labelWarning.Visible = true;
    1.37              }
    1.38              else
    1.39 @@ -167,7 +171,7 @@
    1.40              //Bitmap bmpToSave = new Bitmap(bmp);
    1.41              bmp.Save("D:\\capture.png");
    1.42  
    1.43 -            marqueeLabelTop.Text = "Sweet";
    1.44 +            ((MarqueeLabel)tableLayoutPanel.Controls[0]).Text = "Captured";
    1.45  
    1.46              /*
    1.47              string outputFileName = "d:\\capture.png";
    1.48 @@ -307,8 +311,12 @@
    1.49              //Update our animations
    1.50              DateTime NewTickTime = DateTime.Now;
    1.51  
    1.52 -            marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
    1.53 -            marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
    1.54 +            //Update animation for all our marquees
    1.55 +            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
    1.56 +            {
    1.57 +                ctrl.UpdateAnimation(LastTickTime, NewTickTime);
    1.58 +            }
    1.59 +
    1.60  
    1.61              //Update our display
    1.62              if (iDisplay.IsOpen())
    1.63 @@ -464,8 +472,13 @@
    1.64              //Load settings
    1.65              checkBoxShowBorders.Checked = cds.ShowBorders;
    1.66              tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
    1.67 -            marqueeLabelTop.Font = cds.Font;
    1.68 -            marqueeLabelBottom.Font = cds.Font;
    1.69 +
    1.70 +            //Set the proper font to each of our labels
    1.71 +            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
    1.72 +            {
    1.73 +                ctrl.Font = cds.Font;
    1.74 +            }
    1.75 +
    1.76              CheckFontHeight();
    1.77              checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
    1.78              checkBoxReverseScreen.Checked = cds.ReverseScreen;
    1.79 @@ -770,19 +783,10 @@
    1.80                      client.Texts[aTextField.Index] = aTextField;
    1.81  
    1.82                      //We are in the proper thread
    1.83 -                    //Only support two lines for now
    1.84 -                    if (aTextField.Index == 0)
    1.85 -                    {
    1.86 -                        marqueeLabelTop.Text = aTextField.Text;
    1.87 -                        marqueeLabelTop.TextAlign = aTextField.Alignment;
    1.88 -                    }
    1.89 -                    else if (aTextField.Index == 1)
    1.90 -                    {
    1.91 -                        marqueeLabelBottom.Text = aTextField.Text;
    1.92 -                        marqueeLabelBottom.TextAlign = aTextField.Alignment;
    1.93 -                    }
    1.94 -
    1.95 -
    1.96 +                    MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index];
    1.97 +                    label.Text = aTextField.Text;
    1.98 +                    label.TextAlign = aTextField.Alignment;
    1.99 +                    //
   1.100                      UpdateClientTreeViewNode(client);
   1.101                  }
   1.102              }
   1.103 @@ -823,16 +827,9 @@
   1.104                      //Only support two lines for now
   1.105                      for (int i = 0; i < aTextFields.Count; i++)
   1.106                      {
   1.107 -                        if (aTextFields[i].Index == 0)
   1.108 -                        {
   1.109 -                            marqueeLabelTop.Text = aTextFields[i].Text;
   1.110 -                            marqueeLabelTop.TextAlign = aTextFields[i].Alignment;
   1.111 -                        }
   1.112 -                        else if (aTextFields[i].Index == 1)
   1.113 -                        {
   1.114 -                            marqueeLabelBottom.Text = aTextFields[i].Text;
   1.115 -                            marqueeLabelBottom.TextAlign = aTextFields[i].Alignment;
   1.116 -                        }
   1.117 +                        MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextFields[i].Index];
   1.118 +                        label.Text = aTextFields[i].Text;
   1.119 +                        label.TextAlign = aTextFields[i].Alignment;
   1.120                      }
   1.121  
   1.122  
   1.123 @@ -935,7 +932,7 @@
   1.124          {
   1.125              if (tableLayoutPanel.RowCount < 6)
   1.126              {
   1.127 -                tableLayoutPanel.RowCount++;
   1.128 +                CreateMarqueeForCell(0, tableLayoutPanel.RowCount);
   1.129                  CheckFontHeight();
   1.130              }
   1.131          }
   1.132 @@ -944,9 +941,58 @@
   1.133          {
   1.134              if (tableLayoutPanel.RowCount > 1)
   1.135              {
   1.136 +                tableLayoutPanel.RowStyles.RemoveAt(tableLayoutPanel.RowCount-1);
   1.137 +                tableLayoutPanel.Controls.RemoveAt(tableLayoutPanel.RowCount-1);
   1.138                  tableLayoutPanel.RowCount--;
   1.139                  CheckFontHeight();
   1.140              }
   1.141 +
   1.142 +            UpdateTableLayoutRowStyles();
   1.143 +        }
   1.144 +
   1.145 +        /// <summary>
   1.146 +        /// Update our table layout row styles to make sure each rows have similar height
   1.147 +        /// </summary>
   1.148 +        private void UpdateTableLayoutRowStyles()
   1.149 +        {
   1.150 +            foreach (RowStyle rowStyle in tableLayoutPanel.RowStyles)
   1.151 +            {
   1.152 +                rowStyle.SizeType = SizeType.Percent;
   1.153 +                rowStyle.Height = 100 / tableLayoutPanel.RowCount;
   1.154 +            }
   1.155 +        }
   1.156 +
   1.157 +        /// <summary>
   1.158 +        /// Create the specified cell in our table layout and add a marquee label to it.
   1.159 +        /// </summary>
   1.160 +        /// <param name="aColumn"></param>
   1.161 +        /// <param name="aRow"></param>
   1.162 +        private void CreateMarqueeForCell(int aColumn, int aRow)
   1.163 +        {
   1.164 +            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize));
   1.165 +            MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
   1.166 +            control.AutoEllipsis = true;
   1.167 +            control.AutoSize = true;
   1.168 +            control.BackColor = System.Drawing.Color.Transparent;
   1.169 +            control.Dock = System.Windows.Forms.DockStyle.Fill;
   1.170 +            control.Location = new System.Drawing.Point(1, 1);
   1.171 +            control.Margin = new System.Windows.Forms.Padding(0);
   1.172 +            control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
   1.173 +            control.OwnTimer = false;
   1.174 +            control.PixelsPerSecond = 64;
   1.175 +            control.Separator = "|";
   1.176 +            //control.Size = new System.Drawing.Size(254, 30);
   1.177 +            //control.TabIndex = 2;
   1.178 +            control.Font = cds.Font;
   1.179 +            control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
   1.180 +            control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   1.181 +            control.UseCompatibleTextRendering = true;
   1.182 +            //
   1.183 +            tableLayoutPanel.RowCount++;
   1.184 +            tableLayoutPanel.Controls.Add(control, aColumn, aRow);
   1.185 +
   1.186 +            UpdateTableLayoutRowStyles();
   1.187 +
   1.188          }
   1.189  
   1.190          private void buttonAddColumn_Click(object sender, EventArgs e)
   1.191 @@ -969,20 +1015,26 @@
   1.192  
   1.193          private void buttonAlignLeft_Click(object sender, EventArgs e)
   1.194          {
   1.195 -            marqueeLabelTop.TextAlign = ContentAlignment.MiddleLeft;
   1.196 -            marqueeLabelBottom.TextAlign = ContentAlignment.MiddleLeft;
   1.197 +            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
   1.198 +            {
   1.199 +                ctrl.TextAlign = ContentAlignment.MiddleLeft;
   1.200 +            }
   1.201          }
   1.202  
   1.203          private void buttonAlignCenter_Click(object sender, EventArgs e)
   1.204          {
   1.205 -            marqueeLabelTop.TextAlign = ContentAlignment.MiddleCenter;
   1.206 -            marqueeLabelBottom.TextAlign = ContentAlignment.MiddleCenter;
   1.207 +            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
   1.208 +            {
   1.209 +                ctrl.TextAlign = ContentAlignment.MiddleCenter;
   1.210 +            }
   1.211          }
   1.212  
   1.213          private void buttonAlignRight_Click(object sender, EventArgs e)
   1.214          {
   1.215 -            marqueeLabelTop.TextAlign = ContentAlignment.MiddleRight;
   1.216 -            marqueeLabelBottom.TextAlign = ContentAlignment.MiddleRight;
   1.217 +            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
   1.218 +            {
   1.219 +                ctrl.TextAlign = ContentAlignment.MiddleRight;
   1.220 +            }
   1.221          }
   1.222  
   1.223          private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e)
   1.224 @@ -1035,7 +1087,6 @@
   1.225          {
   1.226              iDisplay.HideClock();
   1.227          }
   1.228 -
   1.229      }
   1.230  
   1.231      /// <summary>