Bitmap field now mostly working.
authorsl
Mon, 13 Oct 2014 21:21:53 +0200
changeset 681d0cd5e6e0a9
parent 67 6e50baf5a811
child 69 2add30edb508
Bitmap field now mostly working.
Client/MainForm.Designer.cs
Client/MainForm.cs
Server/MainForm.cs
     1.1 --- a/Client/MainForm.Designer.cs	Mon Oct 13 20:05:48 2014 +0200
     1.2 +++ b/Client/MainForm.Designer.cs	Mon Oct 13 21:21:53 2014 +0200
     1.3 @@ -36,7 +36,7 @@
     1.4              this.buttonAlignLeft = new System.Windows.Forms.Button();
     1.5              this.buttonSetTopText = new System.Windows.Forms.Button();
     1.6              this.buttonLayoutUpdate = new System.Windows.Forms.Button();
     1.7 -            this.button1 = new System.Windows.Forms.Button();
     1.8 +            this.buttonSetBitmap = new System.Windows.Forms.Button();
     1.9              this.SuspendLayout();
    1.10              // 
    1.11              // buttonSetText
    1.12 @@ -113,22 +113,22 @@
    1.13              this.buttonLayoutUpdate.UseVisualStyleBackColor = true;
    1.14              this.buttonLayoutUpdate.Click += new System.EventHandler(this.buttonLayoutUpdate_Click);
    1.15              // 
    1.16 -            // button1
    1.17 +            // buttonSetBitmap
    1.18              // 
    1.19 -            this.button1.Location = new System.Drawing.Point(12, 190);
    1.20 -            this.button1.Name = "button1";
    1.21 -            this.button1.Size = new System.Drawing.Size(75, 23);
    1.22 -            this.button1.TabIndex = 26;
    1.23 -            this.button1.Text = "Set Bitmap";
    1.24 -            this.button1.UseVisualStyleBackColor = true;
    1.25 -            this.button1.Click += new System.EventHandler(this.button1_Click);
    1.26 +            this.buttonSetBitmap.Location = new System.Drawing.Point(12, 190);
    1.27 +            this.buttonSetBitmap.Name = "buttonSetBitmap";
    1.28 +            this.buttonSetBitmap.Size = new System.Drawing.Size(75, 23);
    1.29 +            this.buttonSetBitmap.TabIndex = 26;
    1.30 +            this.buttonSetBitmap.Text = "Set Bitmap";
    1.31 +            this.buttonSetBitmap.UseVisualStyleBackColor = true;
    1.32 +            this.buttonSetBitmap.Click += new System.EventHandler(this.buttonSetBitmap_Click);
    1.33              // 
    1.34              // MainForm
    1.35              // 
    1.36              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    1.37              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    1.38              this.ClientSize = new System.Drawing.Size(443, 252);
    1.39 -            this.Controls.Add(this.button1);
    1.40 +            this.Controls.Add(this.buttonSetBitmap);
    1.41              this.Controls.Add(this.buttonLayoutUpdate);
    1.42              this.Controls.Add(this.buttonSetTopText);
    1.43              this.Controls.Add(this.buttonAlignRight);
    1.44 @@ -156,7 +156,7 @@
    1.45          private System.Windows.Forms.Button buttonAlignLeft;
    1.46          private System.Windows.Forms.Button buttonSetTopText;
    1.47          private System.Windows.Forms.Button buttonLayoutUpdate;
    1.48 -        private System.Windows.Forms.Button button1;
    1.49 +        private System.Windows.Forms.Button buttonSetBitmap;
    1.50      }
    1.51  }
    1.52  
     2.1 --- a/Client/MainForm.cs	Mon Oct 13 20:05:48 2014 +0200
     2.2 +++ b/Client/MainForm.cs	Mon Oct 13 21:21:53 2014 +0200
     2.3 @@ -160,19 +160,21 @@
     2.4              iClient.SetLayout(layout);
     2.5          }
     2.6  
     2.7 -        private void button1_Click(object sender, EventArgs e)
     2.8 +        private void buttonSetBitmap_Click(object sender, EventArgs e)
     2.9          {
    2.10 -            Bitmap bitmap = new Bitmap(60,60);
    2.11 +            int x1 = 0;
    2.12 +            int y1 = 0;
    2.13 +            int x2 = 256;
    2.14 +            int y2 = 32;
    2.15 +
    2.16 +            Bitmap bitmap = new Bitmap(x2,y2);
    2.17              Pen blackPen = new Pen(Color.Black, 3);
    2.18  
    2.19 -            int x1 = 0;
    2.20 -            int y1 = 0;
    2.21 -            int x2 = 60;
    2.22 -            int y2 = 60;
    2.23              // Draw line to screen.
    2.24              using (var graphics = Graphics.FromImage(bitmap))
    2.25              {
    2.26                  graphics.DrawLine(blackPen, x1, y1, x2, y2);
    2.27 +                graphics.DrawLine(blackPen, x1, y2, x2, y1);
    2.28              }
    2.29  
    2.30              iClient.SetBitmap(new BitmapField(0, bitmap));
     3.1 --- a/Server/MainForm.cs	Mon Oct 13 20:05:48 2014 +0200
     3.2 +++ b/Server/MainForm.cs	Mon Oct 13 21:21:53 2014 +0200
     3.3 @@ -160,9 +160,19 @@
     3.4                  labelFontWidth.Text = "Font width: " + charWidth;
     3.5              }
     3.6  
     3.7 +            MarqueeLabel label = null;            
     3.8 +            //Get the first label control we can find
     3.9 +            foreach (Control ctrl in tableLayoutPanel.Controls)
    3.10 +            {
    3.11 +                if (ctrl is MarqueeLabel)
    3.12 +                {
    3.13 +                    label = (MarqueeLabel)ctrl;
    3.14 +                    break;
    3.15 +                }
    3.16 +            }
    3.17 +
    3.18              //Now check font height and show a warning if needed.
    3.19 -            MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[0];
    3.20 -            if (label.Font.Height > label.Height)
    3.21 +            if (label != null && label.Font.Height > label.Height)
    3.22              {
    3.23                  labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!";
    3.24                  labelWarning.Visible = true;
    3.25 @@ -322,9 +332,12 @@
    3.26              DateTime NewTickTime = DateTime.Now;
    3.27  
    3.28              //Update animation for all our marquees
    3.29 -            foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
    3.30 +            foreach (Control ctrl in tableLayoutPanel.Controls)
    3.31              {
    3.32 -                ctrl.UpdateAnimation(LastTickTime, NewTickTime);
    3.33 +                if (ctrl is MarqueeLabel)
    3.34 +                {
    3.35 +                    ((MarqueeLabel)ctrl).UpdateAnimation(LastTickTime, NewTickTime);
    3.36 +                }
    3.37              }
    3.38  
    3.39  
    3.40 @@ -813,9 +826,17 @@
    3.41                      client.Fields[aTextField.Index] = aTextField;
    3.42  
    3.43                      //We are in the proper thread
    3.44 -                    MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index];
    3.45 -                    label.Text = aTextField.Text;
    3.46 -                    label.TextAlign = aTextField.Alignment;
    3.47 +                    if (tableLayoutPanel.Controls[aTextField.Index] is MarqueeLabel)
    3.48 +                    {
    3.49 +                        MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index];
    3.50 +                        label.Text = aTextField.Text;
    3.51 +                        label.TextAlign = aTextField.Alignment;
    3.52 +                    }
    3.53 +                    else
    3.54 +                    {
    3.55 +                        //Wrong control type, re-create them all
    3.56 +                        UpdateTableLayoutPanel(iCurrentClientData);
    3.57 +                    }
    3.58                      //
    3.59                      UpdateClientTreeViewNode(client);
    3.60                  }
    3.61 @@ -856,11 +877,22 @@
    3.62                          j++;
    3.63                      }
    3.64                      //Put each our text fields in a label control
    3.65 -                    for (int i = 0; i < aTextFields.Count; i++)
    3.66 +                    foreach (TextField field in aTextFields)
    3.67                      {
    3.68 -                        MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextFields[i].Index];
    3.69 -                        label.Text = aTextFields[i].Text;
    3.70 -                        label.TextAlign = aTextFields[i].Alignment;
    3.71 +                        if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel)
    3.72 +                        {
    3.73 +                            //Proper control type just update the text
    3.74 +                            MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[field.Index];
    3.75 +                            label.Text = field.Text;
    3.76 +                            label.TextAlign = field.Alignment;
    3.77 +                        }
    3.78 +                        else
    3.79 +                        {
    3.80 +                            //Wrong control for the given field
    3.81 +                            //Update our layout thus re-creating our controls
    3.82 +                            UpdateTableLayoutPanel(iCurrentClientData);
    3.83 +                            break; //No need to keep on looping layout update will take care of everything
    3.84 +                        }
    3.85                      }
    3.86  
    3.87  
    3.88 @@ -898,8 +930,16 @@
    3.89                      client.Fields[aBitmapField.Index] = aBitmapField;
    3.90  
    3.91                      //We are in the proper thread
    3.92 -                    MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aBitmapField.Index];
    3.93 -                    label.Text = "Bitmap";
    3.94 +                    if (tableLayoutPanel.Controls[aBitmapField.Index] is PictureBox)
    3.95 +                    {
    3.96 +                        PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aBitmapField.Index];
    3.97 +                        pictureBox.Image = aBitmapField.Bitmap;
    3.98 +                    }
    3.99 +                    else
   3.100 +                    {
   3.101 +                        //Wrong control type re-create them all
   3.102 +                        UpdateTableLayoutPanel(iCurrentClientData);
   3.103 +                    }
   3.104                      //
   3.105                      UpdateClientTreeViewNode(client);
   3.106                  }
   3.107 @@ -1156,21 +1196,26 @@
   3.108                          this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]);
   3.109                      }
   3.110  
   3.111 -                    MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
   3.112 -                    control.AutoEllipsis = true;
   3.113 -                    control.AutoSize = true;
   3.114 -                    control.BackColor = System.Drawing.Color.Transparent;
   3.115 -                    control.Dock = System.Windows.Forms.DockStyle.Fill;
   3.116 -                    control.Location = new System.Drawing.Point(1, 1);
   3.117 -                    control.Margin = new System.Windows.Forms.Padding(0);
   3.118 -                    control.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count;
   3.119 -                    control.OwnTimer = false;
   3.120 -                    control.PixelsPerSecond = 64;
   3.121 -                    control.Separator = "|";
   3.122 +
   3.123 +                    MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
   3.124 +                    label.AutoEllipsis = true;
   3.125 +                    label.AutoSize = true;
   3.126 +                    label.BackColor = System.Drawing.Color.Transparent;
   3.127 +                    label.Dock = System.Windows.Forms.DockStyle.Fill;
   3.128 +                    label.Location = new System.Drawing.Point(1, 1);
   3.129 +                    label.Margin = new System.Windows.Forms.Padding(0);
   3.130 +                    label.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count;
   3.131 +                    label.OwnTimer = false;
   3.132 +                    label.PixelsPerSecond = 64;
   3.133 +                    label.Separator = "|";
   3.134                      //control.Size = new System.Drawing.Size(254, 30);
   3.135                      //control.TabIndex = 2;
   3.136 -                    control.Font = cds.Font;
   3.137 -                    control.Text = "";
   3.138 +                    label.Font = cds.Font;
   3.139 +                    label.Text = "";
   3.140 +                    label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   3.141 +                    label.UseCompatibleTextRendering = true;
   3.142 +
   3.143 +                    Control control = label;
   3.144                      //If we already have a text for that field
   3.145                      if (aClient.Fields.Count > tableLayoutPanel.Controls.Count)
   3.146                      {
   3.147 @@ -1180,10 +1225,24 @@
   3.148                              TextField textField = (TextField)field;
   3.149                              control.Text = textField.Text;
   3.150                          }
   3.151 +                        else if (field is BitmapField)
   3.152 +                        {
   3.153 +                            //Create picture box
   3.154 +                            PictureBox pictue = new PictureBox();
   3.155 +                            pictue.AutoSize = true;
   3.156 +                            pictue.BackColor = System.Drawing.Color.Transparent;
   3.157 +                            pictue.Dock = System.Windows.Forms.DockStyle.Fill;
   3.158 +                            pictue.Location = new System.Drawing.Point(1, 1);
   3.159 +                            pictue.Margin = new System.Windows.Forms.Padding(0);
   3.160 +                            pictue.Name = "pictureBox" + layout.Columns.Count + "Row" + layout.Rows.Count;
   3.161 +                            //Set our image
   3.162 +                            BitmapField bitmapField = (BitmapField)field;
   3.163 +                            pictue.Image = bitmapField.Bitmap;
   3.164 +                            //
   3.165 +                            control = pictue;
   3.166 +                        }
   3.167                      }
   3.168 -                    
   3.169 -                    control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   3.170 -                    control.UseCompatibleTextRendering = true;
   3.171 +
   3.172                      //
   3.173                      tableLayoutPanel.Controls.Add(control, i, j);
   3.174                  }
   3.175 @@ -1192,6 +1251,56 @@
   3.176              CheckFontHeight();
   3.177          }
   3.178  
   3.179 +        /// <summary>
   3.180 +        /// Not used yet.
   3.181 +        /// </summary>
   3.182 +        /// <param name="aField"></param>
   3.183 +        private void CreateControlForDataField(DataField aField)
   3.184 +        {
   3.185 +            Control control=null;
   3.186 +            if (aField is TextField)
   3.187 +            {
   3.188 +                MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
   3.189 +                label.AutoEllipsis = true;
   3.190 +                label.AutoSize = true;
   3.191 +                label.BackColor = System.Drawing.Color.Transparent;
   3.192 +                label.Dock = System.Windows.Forms.DockStyle.Fill;
   3.193 +                label.Location = new System.Drawing.Point(1, 1);
   3.194 +                label.Margin = new System.Windows.Forms.Padding(0);
   3.195 +                label.Name = "marqueeLabel" + aField.Index;
   3.196 +                label.OwnTimer = false;
   3.197 +                label.PixelsPerSecond = 64;
   3.198 +                label.Separator = "|";
   3.199 +                //control.Size = new System.Drawing.Size(254, 30);
   3.200 +                //control.TabIndex = 2;
   3.201 +                label.Font = cds.Font;
   3.202 +
   3.203 +                label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   3.204 +                label.UseCompatibleTextRendering = true;
   3.205 +                TextField textField = (TextField)aField;
   3.206 +                label.Text = textField.Text;
   3.207 +                //
   3.208 +                control = label;
   3.209 +            }
   3.210 +            else if (aField is BitmapField)
   3.211 +            {
   3.212 +                //Create picture box
   3.213 +                PictureBox picture = new PictureBox();
   3.214 +                picture.AutoSize = true;
   3.215 +                picture.BackColor = System.Drawing.Color.Transparent;
   3.216 +                picture.Dock = System.Windows.Forms.DockStyle.Fill;
   3.217 +                picture.Location = new System.Drawing.Point(1, 1);
   3.218 +                picture.Margin = new System.Windows.Forms.Padding(0);
   3.219 +                picture.Name = "pictureBox" + aField;
   3.220 +                //Set our image
   3.221 +                BitmapField bitmapField = (BitmapField)aField;
   3.222 +                picture.Image = bitmapField.Bitmap;
   3.223 +                //
   3.224 +                control = picture;
   3.225 +            }
   3.226 +
   3.227 +        }
   3.228 +
   3.229  
   3.230          private void buttonAlignLeft_Click(object sender, EventArgs e)
   3.231          {