Server/MainForm.cs
changeset 61 5a24e79384be
parent 60 4f2a73683adc
child 62 ac698f4e1b36
     1.1 --- a/Server/MainForm.cs	Mon Sep 22 13:00:27 2014 +0200
     1.2 +++ b/Server/MainForm.cs	Mon Sep 22 13:21:00 2014 +0200
     1.3 @@ -932,7 +932,7 @@
     1.4          {
     1.5              if (tableLayoutPanel.RowCount < 6)
     1.6              {
     1.7 -                CreateMarqueeForCell(0, tableLayoutPanel.RowCount);
     1.8 +                RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount + 1);
     1.9                  CheckFontHeight();
    1.10              }
    1.11          }
    1.12 @@ -941,9 +941,7 @@
    1.13          {
    1.14              if (tableLayoutPanel.RowCount > 1)
    1.15              {
    1.16 -                tableLayoutPanel.RowStyles.RemoveAt(tableLayoutPanel.RowCount-1);
    1.17 -                tableLayoutPanel.Controls.RemoveAt(tableLayoutPanel.RowCount-1);
    1.18 -                tableLayoutPanel.RowCount--;
    1.19 +                RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount - 1);
    1.20                  CheckFontHeight();
    1.21              }
    1.22  
    1.23 @@ -963,43 +961,70 @@
    1.24          }
    1.25  
    1.26          /// <summary>
    1.27 -        /// Create the specified cell in our table layout and add a marquee label to it.
    1.28 +        /// Empty and recreate our table layout with the given number of columns and rows.
    1.29 +        /// Sizes of rows and columns are uniform.
    1.30          /// </summary>
    1.31          /// <param name="aColumn"></param>
    1.32          /// <param name="aRow"></param>
    1.33 -        private void CreateMarqueeForCell(int aColumn, int aRow)
    1.34 +        private void RecreateTableLayoutPanel(int aColumn, int aRow)
    1.35          {
    1.36 -            this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize));
    1.37 -            MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
    1.38 -            control.AutoEllipsis = true;
    1.39 -            control.AutoSize = true;
    1.40 -            control.BackColor = System.Drawing.Color.Transparent;
    1.41 -            control.Dock = System.Windows.Forms.DockStyle.Fill;
    1.42 -            control.Location = new System.Drawing.Point(1, 1);
    1.43 -            control.Margin = new System.Windows.Forms.Padding(0);
    1.44 -            control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
    1.45 -            control.OwnTimer = false;
    1.46 -            control.PixelsPerSecond = 64;
    1.47 -            control.Separator = "|";
    1.48 -            //control.Size = new System.Drawing.Size(254, 30);
    1.49 -            //control.TabIndex = 2;
    1.50 -            control.Font = cds.Font;
    1.51 -            control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
    1.52 -            control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.53 -            control.UseCompatibleTextRendering = true;
    1.54 -            //
    1.55 -            tableLayoutPanel.RowCount++;
    1.56 -            tableLayoutPanel.Controls.Add(control, aColumn, aRow);
    1.57 +            tableLayoutPanel.Controls.Clear();
    1.58 +            tableLayoutPanel.RowStyles.Clear();
    1.59 +            tableLayoutPanel.ColumnStyles.Clear();
    1.60 +            tableLayoutPanel.RowCount = 0;
    1.61 +            tableLayoutPanel.ColumnCount = 0;
    1.62  
    1.63 -            UpdateTableLayoutRowStyles();
    1.64 +            while (tableLayoutPanel.RowCount < aRow)
    1.65 +            {
    1.66 +                tableLayoutPanel.RowCount++;
    1.67 +            }
    1.68  
    1.69 +            while (tableLayoutPanel.ColumnCount < aColumn)
    1.70 +            {
    1.71 +                tableLayoutPanel.ColumnCount++;
    1.72 +            }
    1.73 +
    1.74 +            for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
    1.75 +            {
    1.76 +                //Create our column styles
    1.77 +                this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.ColumnCount));
    1.78 +
    1.79 +                for (int j = 0; j < tableLayoutPanel.RowCount; j++)
    1.80 +                {
    1.81 +                    if (i == 0)
    1.82 +                    {
    1.83 +                        //Create our row styles
    1.84 +                        this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.RowCount));
    1.85 +                    }
    1.86 +
    1.87 +                    MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
    1.88 +                    control.AutoEllipsis = true;
    1.89 +                    control.AutoSize = true;
    1.90 +                    control.BackColor = System.Drawing.Color.Transparent;
    1.91 +                    control.Dock = System.Windows.Forms.DockStyle.Fill;
    1.92 +                    control.Location = new System.Drawing.Point(1, 1);
    1.93 +                    control.Margin = new System.Windows.Forms.Padding(0);
    1.94 +                    control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
    1.95 +                    control.OwnTimer = false;
    1.96 +                    control.PixelsPerSecond = 64;
    1.97 +                    control.Separator = "|";
    1.98 +                    //control.Size = new System.Drawing.Size(254, 30);
    1.99 +                    //control.TabIndex = 2;
   1.100 +                    control.Font = cds.Font;
   1.101 +                    control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
   1.102 +                    control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   1.103 +                    control.UseCompatibleTextRendering = true;
   1.104 +                    //
   1.105 +                    tableLayoutPanel.Controls.Add(control, i, j);
   1.106 +                }
   1.107 +            }
   1.108          }
   1.109  
   1.110          private void buttonAddColumn_Click(object sender, EventArgs e)
   1.111          {
   1.112              if (tableLayoutPanel.ColumnCount < 8)
   1.113              {
   1.114 -                tableLayoutPanel.ColumnCount++;
   1.115 +                RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount + 1, tableLayoutPanel.RowCount);
   1.116                  //CheckFontHeight();
   1.117              }
   1.118          }
   1.119 @@ -1008,7 +1033,7 @@
   1.120          {
   1.121              if (tableLayoutPanel.ColumnCount > 1)
   1.122              {
   1.123 -                tableLayoutPanel.ColumnCount--;
   1.124 +                RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount - 1, tableLayoutPanel.RowCount);
   1.125                  //CheckFontHeight();
   1.126              }
   1.127          }