Server/MainForm.cs
changeset 105 4196b0ca97d9
parent 104 189aac7dd3d6
child 106 32270ff62819
     1.1 --- a/Server/MainForm.cs	Wed Feb 04 17:44:25 2015 +0100
     1.2 +++ b/Server/MainForm.cs	Wed Feb 04 21:55:45 2015 +0100
     1.3 @@ -108,6 +108,14 @@
     1.4  		/// <param name="aDisplay"></param>
     1.5  		private void OnDisplayOpened(Display aDisplay)
     1.6  		{
     1.7 +			//Set our screen size now that our display is connected
     1.8 +			//Our panelDisplay is the container of our tableLayoutPanel
     1.9 +			//tableLayoutPanel will resize itself to fit the client size of our panelDisplay
    1.10 +			//panelDisplay needs an extra 2 pixels for borders on each sides
    1.11 +			//tableLayoutPanel will eventually be the exact size of our display
    1.12 +			Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2);
    1.13 +			panelDisplay.Size = size;
    1.14 +
    1.15  			//Our display was just opened, update our UI
    1.16  			UpdateStatus();
    1.17  			//Initiate asynchronous request
    1.18 @@ -692,18 +700,29 @@
    1.19  				//We have a display connection
    1.20  				//Reflect that in our UI
    1.21  
    1.22 -				//Set our screen size
    1.23 -				tableLayoutPanel.Width = iDisplay.WidthInPixels();
    1.24 -				tableLayoutPanel.Height = iDisplay.HeightInPixels();
    1.25  				tableLayoutPanel.Enabled = true;
    1.26 +				panelDisplay.Enabled = true;
    1.27  
    1.28                  //Only setup brightness if display is open
    1.29                  trackBarBrightness.Minimum = iDisplay.MinBrightness();
    1.30                  trackBarBrightness.Maximum = iDisplay.MaxBrightness();
    1.31 -                trackBarBrightness.Value = cds.Brightness;
    1.32 +				if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness())
    1.33 +				{
    1.34 +					//Brightness out of range, this can occur when using auto-detect
    1.35 +					//Use max brightness instead
    1.36 +					trackBarBrightness.Value = iDisplay.MaxBrightness();
    1.37 +					iDisplay.SetBrightness(iDisplay.MaxBrightness());
    1.38 +				}
    1.39 +				else
    1.40 +				{
    1.41 +					trackBarBrightness.Value = cds.Brightness;
    1.42 +					iDisplay.SetBrightness(cds.Brightness);
    1.43 +				}
    1.44 +
    1.45 +				//Try compute the steps to something that makes sense
    1.46                  trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5);
    1.47                  trackBarBrightness.SmallChange = 1;
    1.48 -                iDisplay.SetBrightness(cds.Brightness);
    1.49 +                
    1.50                  //
    1.51                  buttonFill.Enabled = true;
    1.52                  buttonClear.Enabled = true;
    1.53 @@ -740,6 +759,7 @@
    1.54  				//Display is connection not available
    1.55  				//Reflect that in our UI
    1.56  				tableLayoutPanel.Enabled = false;
    1.57 +				panelDisplay.Enabled = false;
    1.58                  buttonFill.Enabled = false;
    1.59                  buttonClear.Enabled = false;
    1.60                  buttonOpen.Enabled = true;
    1.61 @@ -831,6 +851,7 @@
    1.62  
    1.63          private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    1.64          {
    1.65 +			CloseDisplayConnection();
    1.66              StopServer();
    1.67              e.Cancel = iClosing;
    1.68          }
    1.69 @@ -1700,8 +1721,17 @@
    1.70  
    1.71  		}
    1.72  
    1.73 -
    1.74 -
    1.75 +		/// <summary>
    1.76 +		/// 
    1.77 +		/// </summary>
    1.78 +		/// <param name="sender"></param>
    1.79 +		/// <param name="e"></param>
    1.80 +		private void tableLayoutPanel_SizeChanged(object sender, EventArgs e)
    1.81 +		{
    1.82 +			//Our table layout size has changed which means our display size has changed.
    1.83 +			//We need to re-create our bitmap.
    1.84 +			iCreateBitmap = true;
    1.85 +		}
    1.86  
    1.87      }
    1.88