# HG changeset patch
# User sl
# Date 1411384860 -7200
# Node ID 5a24e79384be694232f0c156b0e3866b043a240b
# Parent 4f2a73683adc5ec5b6ef23bd56069ee36a53886a
Implement generic function to regenerate our display table layout.
Add and remove column now working.
diff -r 4f2a73683adc -r 5a24e79384be Server/MainForm.cs
--- a/Server/MainForm.cs Mon Sep 22 13:00:27 2014 +0200
+++ b/Server/MainForm.cs Mon Sep 22 13:21:00 2014 +0200
@@ -932,7 +932,7 @@
{
if (tableLayoutPanel.RowCount < 6)
{
- CreateMarqueeForCell(0, tableLayoutPanel.RowCount);
+ RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount + 1);
CheckFontHeight();
}
}
@@ -941,9 +941,7 @@
{
if (tableLayoutPanel.RowCount > 1)
{
- tableLayoutPanel.RowStyles.RemoveAt(tableLayoutPanel.RowCount-1);
- tableLayoutPanel.Controls.RemoveAt(tableLayoutPanel.RowCount-1);
- tableLayoutPanel.RowCount--;
+ RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount - 1);
CheckFontHeight();
}
@@ -963,43 +961,70 @@
}
///
- /// Create the specified cell in our table layout and add a marquee label to it.
+ /// Empty and recreate our table layout with the given number of columns and rows.
+ /// Sizes of rows and columns are uniform.
///
///
///
- private void CreateMarqueeForCell(int aColumn, int aRow)
+ private void RecreateTableLayoutPanel(int aColumn, int aRow)
{
- this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize));
- MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
- control.AutoEllipsis = true;
- control.AutoSize = true;
- control.BackColor = System.Drawing.Color.Transparent;
- control.Dock = System.Windows.Forms.DockStyle.Fill;
- control.Location = new System.Drawing.Point(1, 1);
- control.Margin = new System.Windows.Forms.Padding(0);
- control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
- control.OwnTimer = false;
- control.PixelsPerSecond = 64;
- control.Separator = "|";
- //control.Size = new System.Drawing.Size(254, 30);
- //control.TabIndex = 2;
- control.Font = cds.Font;
- control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
- control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- control.UseCompatibleTextRendering = true;
- //
- tableLayoutPanel.RowCount++;
- tableLayoutPanel.Controls.Add(control, aColumn, aRow);
+ tableLayoutPanel.Controls.Clear();
+ tableLayoutPanel.RowStyles.Clear();
+ tableLayoutPanel.ColumnStyles.Clear();
+ tableLayoutPanel.RowCount = 0;
+ tableLayoutPanel.ColumnCount = 0;
- UpdateTableLayoutRowStyles();
+ while (tableLayoutPanel.RowCount < aRow)
+ {
+ tableLayoutPanel.RowCount++;
+ }
+ while (tableLayoutPanel.ColumnCount < aColumn)
+ {
+ tableLayoutPanel.ColumnCount++;
+ }
+
+ for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
+ {
+ //Create our column styles
+ this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.ColumnCount));
+
+ for (int j = 0; j < tableLayoutPanel.RowCount; j++)
+ {
+ if (i == 0)
+ {
+ //Create our row styles
+ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.RowCount));
+ }
+
+ MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
+ control.AutoEllipsis = true;
+ control.AutoSize = true;
+ control.BackColor = System.Drawing.Color.Transparent;
+ control.Dock = System.Windows.Forms.DockStyle.Fill;
+ control.Location = new System.Drawing.Point(1, 1);
+ control.Margin = new System.Windows.Forms.Padding(0);
+ control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
+ control.OwnTimer = false;
+ control.PixelsPerSecond = 64;
+ control.Separator = "|";
+ //control.Size = new System.Drawing.Size(254, 30);
+ //control.TabIndex = 2;
+ control.Font = cds.Font;
+ control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
+ control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ control.UseCompatibleTextRendering = true;
+ //
+ tableLayoutPanel.Controls.Add(control, i, j);
+ }
+ }
}
private void buttonAddColumn_Click(object sender, EventArgs e)
{
if (tableLayoutPanel.ColumnCount < 8)
{
- tableLayoutPanel.ColumnCount++;
+ RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount + 1, tableLayoutPanel.RowCount);
//CheckFontHeight();
}
}
@@ -1008,7 +1033,7 @@
{
if (tableLayoutPanel.ColumnCount > 1)
{
- tableLayoutPanel.ColumnCount--;
+ RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount - 1, tableLayoutPanel.RowCount);
//CheckFontHeight();
}
}