Fixing issues where layout change would not be detected beccause of partial
authorStephaneLenclud
Thu, 24 Sep 2015 14:35:50 +0200
changeset 158e22bf44c4300
parent 157 0f3e7b21c663
child 159 e7c8c2b500bd
Fixing issues where layout change would not be detected beccause of partial
field similarity between new and older layout.
Therefore we now clear our fields whenever our layout is changed.
Now resetting our create bitmap flag, hoping it will fix our rather large memory
usage when minimized.
Client/MainForm.cs
Server/MainForm.cs
     1.1 --- a/Client/MainForm.cs	Thu Sep 03 20:05:09 2015 +0200
     1.2 +++ b/Client/MainForm.cs	Thu Sep 24 14:35:50 2015 +0200
     1.3 @@ -220,6 +220,16 @@
     1.4              layout.Columns[1].Width = 25F;
     1.5              //Send layout to server
     1.6              iClient.SetLayout(layout);
     1.7 +
     1.8 +            //Set texts
     1.9 +            iClient.CreateFields(new DataField[]
    1.10 +            {                
    1.11 +                new DataField(0, textBoxTop.Text, Alignment),
    1.12 +                new DataField(1, textBoxBottom.Text, Alignment),
    1.13 +                new DataField(2, "Third text field", Alignment),
    1.14 +                new DataField(3, "Forth text field", Alignment)
    1.15 +            });
    1.16 +
    1.17          }
    1.18  
    1.19          private void buttonSetBitmap_Click(object sender, EventArgs e)
     2.1 --- a/Server/MainForm.cs	Thu Sep 03 20:05:09 2015 +0200
     2.2 +++ b/Server/MainForm.cs	Thu Sep 24 14:35:50 2015 +0200
     2.3 @@ -133,6 +133,7 @@
     2.4              UpdateStatus();
     2.5  
     2.6              //We have a bug when drawing minimized and reusing our bitmap
     2.7 +            //Though I could not reproduce it on Windows 10
     2.8              iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
     2.9              iCreateBitmap = false;
    2.10  
    2.11 @@ -879,8 +880,9 @@
    2.12  					//Draw to bitmap
    2.13  					if (iCreateBitmap)
    2.14  					{
    2.15 -						iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    2.16 -					}
    2.17 +                        iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    2.18 +                        iCreateBitmap = false;
    2.19 +                    }
    2.20  					tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
    2.21  					//iBmp.Save("D:\\capture.png");
    2.22  
    2.23 @@ -1269,8 +1271,8 @@
    2.24          {
    2.25              if (WindowState == FormWindowState.Minimized)
    2.26              {
    2.27 -                // Do some stuff
    2.28 -                //iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
    2.29 +                // To workaround our empty bitmap bug on Windows 7 we need to recreate our bitmap when the application is minimized
    2.30 +                // That's apparently not needed on Windows 10 but we better leave it in place.
    2.31                  iCreateBitmap = true;
    2.32              }
    2.33          }
    2.34 @@ -1502,11 +1504,18 @@
    2.35                      //Don't change a thing if the layout is the same
    2.36                      if (!client.Layout.IsSameAs(aLayout))
    2.37                      {
    2.38 +                        Debug.Print("SetClientLayoutThreadSafe: Layout updated.");
    2.39                          //Set our client layout then
    2.40                          client.Layout = aLayout;
    2.41 +                        //Layout has changed clear our fields then
    2.42 +                        client.Fields.Clear();
    2.43                          //
    2.44                          UpdateClientTreeViewNode(client);
    2.45                      }
    2.46 +                    else
    2.47 +                    {
    2.48 +                        Debug.Print("SetClientLayoutThreadSafe: Layout has not changed.");
    2.49 +                    }
    2.50                  }
    2.51              }
    2.52          }
    2.53 @@ -1553,7 +1562,7 @@
    2.54                  layoutChanged = true;
    2.55              }
    2.56  
    2.57 -            //Now that we know hour fields are in place just update that one
    2.58 +            //Now that we know our fields are in place just update that one
    2.59              client.Fields[aField.Index] = aField;
    2.60  
    2.61              if (client.Fields[aField.Index].IsSameLayout(aField))
    2.62 @@ -1602,6 +1611,14 @@
    2.63                          UpdateTableLayoutPanel(iCurrentClientData);
    2.64                      }
    2.65                  }
    2.66 +                else
    2.67 +                {
    2.68 +                    Debug.Print("Layout has not changed.");
    2.69 +                }
    2.70 +            }
    2.71 +            else
    2.72 +            {
    2.73 +                Debug.Print("WARNING: content and layout have not changed!");
    2.74              }
    2.75  
    2.76              //When a client field is set we try switching to this client to present the new information to our user