Cleaning up control creation code.
authorsl
Mon, 13 Oct 2014 21:42:42 +0200
changeset 692add30edb508
parent 68 1d0cd5e6e0a9
child 70 dcd2bbb90d42
Cleaning up control creation code.
Server/MainForm.cs
     1.1 --- a/Server/MainForm.cs	Mon Oct 13 21:21:53 2014 +0200
     1.2 +++ b/Server/MainForm.cs	Mon Oct 13 21:42:42 2014 +0200
     1.3 @@ -1196,54 +1196,16 @@
     1.4                          this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]);
     1.5                      }
     1.6  
     1.7 -
     1.8 -                    MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
     1.9 -                    label.AutoEllipsis = true;
    1.10 -                    label.AutoSize = true;
    1.11 -                    label.BackColor = System.Drawing.Color.Transparent;
    1.12 -                    label.Dock = System.Windows.Forms.DockStyle.Fill;
    1.13 -                    label.Location = new System.Drawing.Point(1, 1);
    1.14 -                    label.Margin = new System.Windows.Forms.Padding(0);
    1.15 -                    label.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count;
    1.16 -                    label.OwnTimer = false;
    1.17 -                    label.PixelsPerSecond = 64;
    1.18 -                    label.Separator = "|";
    1.19 -                    //control.Size = new System.Drawing.Size(254, 30);
    1.20 -                    //control.TabIndex = 2;
    1.21 -                    label.Font = cds.Font;
    1.22 -                    label.Text = "";
    1.23 -                    label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    1.24 -                    label.UseCompatibleTextRendering = true;
    1.25 -
    1.26 -                    Control control = label;
    1.27 -                    //If we already have a text for that field
    1.28 -                    if (aClient.Fields.Count > tableLayoutPanel.Controls.Count)
    1.29 +                    //Check if a client field already exists for that cell
    1.30 +                    if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count)
    1.31                      {
    1.32 -                        DataField field = aClient.Fields[tableLayoutPanel.Controls.Count];
    1.33 -                        if (field is TextField)
    1.34 -                        {
    1.35 -                            TextField textField = (TextField)field;
    1.36 -                            control.Text = textField.Text;
    1.37 -                        }
    1.38 -                        else if (field is BitmapField)
    1.39 -                        {
    1.40 -                            //Create picture box
    1.41 -                            PictureBox pictue = new PictureBox();
    1.42 -                            pictue.AutoSize = true;
    1.43 -                            pictue.BackColor = System.Drawing.Color.Transparent;
    1.44 -                            pictue.Dock = System.Windows.Forms.DockStyle.Fill;
    1.45 -                            pictue.Location = new System.Drawing.Point(1, 1);
    1.46 -                            pictue.Margin = new System.Windows.Forms.Padding(0);
    1.47 -                            pictue.Name = "pictureBox" + layout.Columns.Count + "Row" + layout.Rows.Count;
    1.48 -                            //Set our image
    1.49 -                            BitmapField bitmapField = (BitmapField)field;
    1.50 -                            pictue.Image = bitmapField.Bitmap;
    1.51 -                            //
    1.52 -                            control = pictue;
    1.53 -                        }
    1.54 +                        //No client field specified, create a text field by default
    1.55 +                        aClient.Fields.Add(new TextField(aClient.Fields.Count));
    1.56                      }
    1.57  
    1.58 -                    //
    1.59 +                    //Create a control corresponding to the field specified for that cell
    1.60 +                    Control control = CreateControlForDataField(aClient.Fields[tableLayoutPanel.Controls.Count]);
    1.61 +                    //Add newly created control to our table layout at the specified row and column
    1.62                      tableLayoutPanel.Controls.Add(control, i, j);
    1.63                  }
    1.64              }
    1.65 @@ -1255,7 +1217,7 @@
    1.66          /// Not used yet.
    1.67          /// </summary>
    1.68          /// <param name="aField"></param>
    1.69 -        private void CreateControlForDataField(DataField aField)
    1.70 +        private Control CreateControlForDataField(DataField aField)
    1.71          {
    1.72              Control control=null;
    1.73              if (aField is TextField)
    1.74 @@ -1299,6 +1261,7 @@
    1.75                  control = picture;
    1.76              }
    1.77  
    1.78 +            return control;
    1.79          }
    1.80  
    1.81