MainForm.cs
author sl
Tue, 08 Jul 2014 11:48:00 +0200
changeset 5 02716ce36263
parent 3 71b55cfd8c05
child 7 69815d19796c
permissions -rw-r--r--
Custom drawing of our Marquee text to avoid warpping, clipping and ellipsis.
     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         }
    26 
    27         private void buttonFont_Click(object sender, EventArgs e)
    28         {
    29             //fontDialog.ShowColor = true;
    30             //fontDialog.ShowApply = true;
    31             fontDialog.ShowEffects = true;
    32             //fontDialog.ShowHelp = true;
    33 
    34             //fontDlg.MaxSize = 40;
    35             //fontDlg.MinSize = 22;
    36 
    37             //fontDialog.Parent = this;
    38             //fontDialog.StartPosition = FormStartPosition.CenterParent;
    39 
    40             //DlgBox.ShowDialog(fontDialog);
    41 
    42             //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
    43             if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
    44             {
    45 
    46                 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
    47 
    48                 //MessageBox.Show("Ok");
    49                 marqueeLabelTop.Font = fontDialog.Font;
    50                 marqueeLabelBottom.Font = fontDialog.Font;
    51                 //label1.Font = fontDlg.Font;
    52                 //textBox1.BackColor = fontDlg.Color;
    53                 //label1.ForeColor = fontDlg.Color;
    54             }
    55         }
    56 
    57         private void buttonCapture_Click(object sender, EventArgs e)
    58         {
    59             System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    60             tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    61             bmp.Save("c:\\capture.png");
    62         }
    63 
    64         private void timer_Tick(object sender, EventArgs e)
    65         {
    66             //Update our animations
    67             DateTime NewTickTime = DateTime.Now;
    68 
    69             marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
    70             marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
    71 
    72             LastTickTime = NewTickTime;
    73 
    74             //Update our display
    75             if (iDisplay.IsOpen())
    76             {
    77                 //Draw to bitmap
    78                 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    79                 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    80                 //Send it to our display 
    81                 for (int i = 0; i < bmp.Width; i++)
    82                 {
    83                     for (int j = 0; j < bmp.Height; j++)
    84                     {
    85                         unchecked
    86                         {
    87                         uint color=(uint)bmp.GetPixel(i, j).ToArgb();
    88                         iDisplay.SetPixel(i, j, Convert.ToInt32(color!=0xFFFFFFFF));
    89                         }
    90                     }
    91                 }
    92 
    93                 iDisplay.SwapBuffers();
    94 
    95             }
    96         }
    97 
    98         private void buttonOpen_Click(object sender, EventArgs e)
    99         {
   100             if (iDisplay.Open())
   101             {
   102                 trackBarBrightness.Minimum = iDisplay.MinBrightness();
   103                 trackBarBrightness.Maximum = iDisplay.MaxBrightness();                
   104             }
   105             
   106         }
   107 
   108         private void buttonClose_Click(object sender, EventArgs e)
   109         {
   110             iDisplay.Close();
   111         }
   112 
   113         private void buttonClear_Click(object sender, EventArgs e)
   114         {
   115             iDisplay.Clear();
   116             iDisplay.SwapBuffers();
   117         }
   118 
   119         private void buttonFill_Click(object sender, EventArgs e)
   120         {
   121             iDisplay.Fill();
   122             iDisplay.SwapBuffers();
   123         }
   124 
   125         private void trackBarBrightness_Scroll(object sender, EventArgs e)
   126         {
   127             iDisplay.SetBrightness(trackBarBrightness.Value);
   128         }
   129     }
   130 }