Adding status bar and managing control status.
2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using CodeProject.Dialog;
12 namespace SharpDisplayManager
14 public partial class MainForm : Form
16 DateTime LastTickTime;
21 LastTickTime = DateTime.Now;
22 iDisplay = new Display();
24 InitializeComponent();
28 private void buttonFont_Click(object sender, EventArgs e)
30 //fontDialog.ShowColor = true;
31 //fontDialog.ShowApply = true;
32 fontDialog.ShowEffects = true;
33 //fontDialog.ShowHelp = true;
35 //fontDlg.MaxSize = 40;
36 //fontDlg.MinSize = 22;
38 //fontDialog.Parent = this;
39 //fontDialog.StartPosition = FormStartPosition.CenterParent;
41 //DlgBox.ShowDialog(fontDialog);
43 //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
44 if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
47 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
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;
58 private void buttonCapture_Click(object sender, EventArgs e)
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");
65 private void timer_Tick(object sender, EventArgs e)
67 //Update our animations
68 DateTime NewTickTime = DateTime.Now;
70 marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
71 marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
73 LastTickTime = NewTickTime;
76 if (iDisplay.IsOpen())
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++)
84 for (int j = 0; j < bmp.Height; j++)
88 uint color=(uint)bmp.GetPixel(i, j).ToArgb();
89 iDisplay.SetPixel(i, j, Convert.ToInt32(color!=0xFFFFFFFF));
94 iDisplay.SwapBuffers();
99 private void buttonOpen_Click(object sender, EventArgs e)
108 toolStripStatusLabelConnect.Text = "Connection error";
113 private void buttonClose_Click(object sender, EventArgs e)
118 private void buttonClear_Click(object sender, EventArgs e)
121 iDisplay.SwapBuffers();
124 private void buttonFill_Click(object sender, EventArgs e)
127 iDisplay.SwapBuffers();
130 private void trackBarBrightness_Scroll(object sender, EventArgs e)
132 iDisplay.SetBrightness(trackBarBrightness.Value);
135 private void UpdateStatus()
137 if (iDisplay.IsOpen())
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";
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";