Adding persistent settings and marquee separator.
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();
27 marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
28 marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
31 private void buttonFont_Click(object sender, EventArgs e)
33 //fontDialog.ShowColor = true;
34 //fontDialog.ShowApply = true;
35 fontDialog.ShowEffects = true;
36 //fontDialog.ShowHelp = true;
38 //fontDlg.MaxSize = 40;
39 //fontDlg.MinSize = 22;
41 //fontDialog.Parent = this;
42 //fontDialog.StartPosition = FormStartPosition.CenterParent;
44 //DlgBox.ShowDialog(fontDialog);
46 //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
47 if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
50 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
52 //MessageBox.Show("Ok");
53 marqueeLabelTop.Font = fontDialog.Font;
54 marqueeLabelBottom.Font = fontDialog.Font;
55 Properties.Settings.Default.DisplayFont = fontDialog.Font;
56 Properties.Settings.Default.Save();
57 //label1.Font = fontDlg.Font;
58 //textBox1.BackColor = fontDlg.Color;
59 //label1.ForeColor = fontDlg.Color;
63 private void buttonCapture_Click(object sender, EventArgs e)
65 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
66 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
67 bmp.Save("c:\\capture.png");
70 private void timer_Tick(object sender, EventArgs e)
72 //Update our animations
73 DateTime NewTickTime = DateTime.Now;
75 marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
76 marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
79 if (iDisplay.IsOpen())
82 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
83 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
84 //Send it to our display
85 for (int i = 0; i < bmp.Width; i++)
87 for (int j = 0; j < bmp.Height; j++)
91 uint color=(uint)bmp.GetPixel(i, j).ToArgb();
92 iDisplay.SetPixel(i, j, Convert.ToInt32(color!=0xFFFFFFFF));
97 iDisplay.SwapBuffers();
101 //Compute instant FPS
102 toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
104 LastTickTime = NewTickTime;
108 private void buttonOpen_Click(object sender, EventArgs e)
117 toolStripStatusLabelConnect.Text = "Connection error";
122 private void buttonClose_Click(object sender, EventArgs e)
127 private void buttonClear_Click(object sender, EventArgs e)
130 iDisplay.SwapBuffers();
133 private void buttonFill_Click(object sender, EventArgs e)
136 iDisplay.SwapBuffers();
139 private void trackBarBrightness_Scroll(object sender, EventArgs e)
141 iDisplay.SetBrightness(trackBarBrightness.Value);
144 private void UpdateStatus()
146 if (iDisplay.IsOpen())
148 buttonFill.Enabled = true;
149 buttonClear.Enabled = true;
150 buttonOpen.Enabled = false;
151 buttonClose.Enabled = true;
152 trackBarBrightness.Enabled = true;
153 trackBarBrightness.Minimum = iDisplay.MinBrightness();
154 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
155 toolStripStatusLabelConnect.Text = "Connected";
159 buttonFill.Enabled = false;
160 buttonClear.Enabled = false;
161 buttonOpen.Enabled = true;
162 buttonClose.Enabled = false;
163 trackBarBrightness.Enabled = false;
164 toolStripStatusLabelConnect.Text = "Not connected";