MainForm.cs
author sl
Tue, 08 Jul 2014 16:41:29 +0200
changeset 7 69815d19796c
parent 4 0825370a7947
child 8 5129c03ab7ba
permissions -rw-r--r--
Adding status bar and managing control status.
     1 ´╗┐using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 using CodeProject.Dialog;
    11 
    12 namespace SharpDisplayManager
    13 {
    14     public partial class MainForm : Form
    15     {
    16         DateTime LastTickTime;
    17         Display iDisplay;
    18 
    19         public MainForm()
    20         {
    21             LastTickTime = DateTime.Now;
    22             iDisplay = new Display();
    23 
    24             InitializeComponent();
    25             UpdateStatus();
    26         }
    27 
    28         private void buttonFont_Click(object sender, EventArgs e)
    29         {
    30             //fontDialog.ShowColor = true;
    31             //fontDialog.ShowApply = true;
    32             fontDialog.ShowEffects = true;
    33             //fontDialog.ShowHelp = true;
    34 
    35             //fontDlg.MaxSize = 40;
    36             //fontDlg.MinSize = 22;
    37 
    38             //fontDialog.Parent = this;
    39             //fontDialog.StartPosition = FormStartPosition.CenterParent;
    40 
    41             //DlgBox.ShowDialog(fontDialog);
    42 
    43             //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
    44             if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
    45             {
    46 
    47                 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
    48 
    49                 //MessageBox.Show("Ok");
    50                 marqueeLabelTop.Font = fontDialog.Font;
    51                 marqueeLabelBottom.Font = fontDialog.Font;
    52                 //label1.Font = fontDlg.Font;
    53                 //textBox1.BackColor = fontDlg.Color;
    54                 //label1.ForeColor = fontDlg.Color;
    55             }
    56         }
    57 
    58         private void buttonCapture_Click(object sender, EventArgs e)
    59         {
    60             System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    61             tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    62             bmp.Save("c:\\capture.png");
    63         }
    64 
    65         private void timer_Tick(object sender, EventArgs e)
    66         {
    67             //Update our animations
    68             DateTime NewTickTime = DateTime.Now;
    69 
    70             marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
    71             marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
    72 
    73             LastTickTime = NewTickTime;
    74 
    75             //Update our display
    76             if (iDisplay.IsOpen())
    77             {
    78                 //Draw to bitmap
    79                 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    80                 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    81                 //Send it to our display
    82                 for (int i = 0; i < bmp.Width; i++)
    83                 {
    84                     for (int j = 0; j < bmp.Height; j++)
    85                     {
    86                         unchecked
    87                         {
    88                         uint color=(uint)bmp.GetPixel(i, j).ToArgb();
    89                         iDisplay.SetPixel(i, j, Convert.ToInt32(color!=0xFFFFFFFF));
    90                         }
    91                     }
    92                 }
    93 
    94                 iDisplay.SwapBuffers();
    95 
    96             }
    97         }
    98 
    99         private void buttonOpen_Click(object sender, EventArgs e)
   100         {
   101             if (iDisplay.Open())
   102             {
   103                 UpdateStatus();
   104             }
   105             else
   106             {
   107                 UpdateStatus();
   108                 toolStripStatusLabelConnect.Text = "Connection error";
   109             }
   110 
   111         }
   112 
   113         private void buttonClose_Click(object sender, EventArgs e)
   114         {
   115             iDisplay.Close();
   116         }
   117 
   118         private void buttonClear_Click(object sender, EventArgs e)
   119         {
   120             iDisplay.Clear();
   121             iDisplay.SwapBuffers();
   122         }
   123 
   124         private void buttonFill_Click(object sender, EventArgs e)
   125         {
   126             iDisplay.Fill();
   127             iDisplay.SwapBuffers();
   128         }
   129 
   130         private void trackBarBrightness_Scroll(object sender, EventArgs e)
   131         {
   132             iDisplay.SetBrightness(trackBarBrightness.Value);
   133         }
   134 
   135         private void UpdateStatus()
   136         {
   137             if (iDisplay.IsOpen())
   138             {
   139                 buttonFill.Enabled = true;
   140                 buttonClear.Enabled = true;
   141                 buttonOpen.Enabled = false;
   142                 buttonClose.Enabled = true;
   143                 trackBarBrightness.Enabled = true;
   144                 trackBarBrightness.Minimum = iDisplay.MinBrightness();
   145                 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
   146                 toolStripStatusLabelConnect.Text = "Connected";
   147             }
   148             else
   149             {
   150                 buttonFill.Enabled = false;
   151                 buttonClear.Enabled = false;
   152                 buttonOpen.Enabled = true;
   153                 buttonClose.Enabled = false;
   154                 trackBarBrightness.Enabled = false;
   155                 toolStripStatusLabelConnect.Text = "Not connected";
   156             }
   157         }
   158 
   159     }
   160 }