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