MainForm.cs
changeset 7 69815d19796c
parent 4 0825370a7947
child 8 5129c03ab7ba
     1.1 --- a/MainForm.cs	Tue Jul 08 15:49:34 2014 +0200
     1.2 +++ b/MainForm.cs	Tue Jul 08 16:41:29 2014 +0200
     1.3 @@ -22,6 +22,7 @@
     1.4              iDisplay = new Display();
     1.5  
     1.6              InitializeComponent();
     1.7 +            UpdateStatus();
     1.8          }
     1.9  
    1.10          private void buttonFont_Click(object sender, EventArgs e)
    1.11 @@ -77,7 +78,7 @@
    1.12                  //Draw to bitmap
    1.13                  System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    1.14                  tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    1.15 -                //Send it to our display 
    1.16 +                //Send it to our display
    1.17                  for (int i = 0; i < bmp.Width; i++)
    1.18                  {
    1.19                      for (int j = 0; j < bmp.Height; j++)
    1.20 @@ -99,10 +100,14 @@
    1.21          {
    1.22              if (iDisplay.Open())
    1.23              {
    1.24 -                trackBarBrightness.Minimum = iDisplay.MinBrightness();
    1.25 -                trackBarBrightness.Maximum = iDisplay.MaxBrightness();                
    1.26 +                UpdateStatus();
    1.27              }
    1.28 -            
    1.29 +            else
    1.30 +            {
    1.31 +                UpdateStatus();
    1.32 +                toolStripStatusLabelConnect.Text = "Connection error";
    1.33 +            }
    1.34 +
    1.35          }
    1.36  
    1.37          private void buttonClose_Click(object sender, EventArgs e)
    1.38 @@ -126,5 +131,30 @@
    1.39          {
    1.40              iDisplay.SetBrightness(trackBarBrightness.Value);
    1.41          }
    1.42 +
    1.43 +        private void UpdateStatus()
    1.44 +        {
    1.45 +            if (iDisplay.IsOpen())
    1.46 +            {
    1.47 +                buttonFill.Enabled = true;
    1.48 +                buttonClear.Enabled = true;
    1.49 +                buttonOpen.Enabled = false;
    1.50 +                buttonClose.Enabled = true;
    1.51 +                trackBarBrightness.Enabled = true;
    1.52 +                trackBarBrightness.Minimum = iDisplay.MinBrightness();
    1.53 +                trackBarBrightness.Maximum = iDisplay.MaxBrightness();
    1.54 +                toolStripStatusLabelConnect.Text = "Connected";
    1.55 +            }
    1.56 +            else
    1.57 +            {
    1.58 +                buttonFill.Enabled = false;
    1.59 +                buttonClear.Enabled = false;
    1.60 +                buttonOpen.Enabled = true;
    1.61 +                buttonClose.Enabled = false;
    1.62 +                trackBarBrightness.Enabled = false;
    1.63 +                toolStripStatusLabelConnect.Text = "Not connected";
    1.64 +            }
    1.65 +        }
    1.66 +
    1.67      }
    1.68  }