Adding option to connect display on startup.
Better show border implementation.
Now having an external container for our display to show an external border.
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 marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
29 marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
30 checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
31 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
33 tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
36 private void MainForm_Load(object sender, EventArgs e)
38 if (Properties.Settings.Default.DisplayConnectOnStartup)
46 private void buttonFont_Click(object sender, EventArgs e)
48 //fontDialog.ShowColor = true;
49 //fontDialog.ShowApply = true;
50 fontDialog.ShowEffects = true;
51 fontDialog.Font = marqueeLabelTop.Font;
52 //fontDialog.ShowHelp = true;
54 //fontDlg.MaxSize = 40;
55 //fontDlg.MinSize = 22;
57 //fontDialog.Parent = this;
58 //fontDialog.StartPosition = FormStartPosition.CenterParent;
60 //DlgBox.ShowDialog(fontDialog);
62 //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
63 if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
66 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
68 //MessageBox.Show("Ok");
69 marqueeLabelTop.Font = fontDialog.Font;
70 marqueeLabelBottom.Font = fontDialog.Font;
71 Properties.Settings.Default.DisplayFont = fontDialog.Font;
72 Properties.Settings.Default.Save();
73 //label1.Font = fontDlg.Font;
74 //textBox1.BackColor = fontDlg.Color;
75 //label1.ForeColor = fontDlg.Color;
79 private void buttonCapture_Click(object sender, EventArgs e)
81 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
82 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
83 bmp.Save("c:\\capture.png");
86 private void CheckForRequestResults()
88 if (iDisplay.IsRequestPending())
90 switch (iDisplay.AttemptRequestCompletion())
92 case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus:
93 if (iDisplay.PowerSupplyStatus())
95 toolStripStatusLabelPower.Text = "ON";
99 toolStripStatusLabelPower.Text = "OFF";
101 //Issue next request then
102 iDisplay.RequestDeviceId();
105 case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId:
106 toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId();
107 //Issue next request then
108 iDisplay.RequestFirmwareRevision();
111 case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision:
112 toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision();
113 //No more request to issue
119 private void timer_Tick(object sender, EventArgs e)
121 //Update our animations
122 DateTime NewTickTime = DateTime.Now;
124 marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
125 marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
128 if (iDisplay.IsOpen())
130 CheckForRequestResults();
133 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
134 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
135 //Send it to our display
136 for (int i = 0; i < bmp.Width; i++)
138 for (int j = 0; j < bmp.Height; j++)
142 uint color=(uint)bmp.GetPixel(i, j).ToArgb();
143 //(checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000)
144 iDisplay.SetPixel(i, j, Convert.ToInt32(color != 0xFFFFFFFF));
149 iDisplay.SwapBuffers();
153 //Compute instant FPS
154 toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
156 LastTickTime = NewTickTime;
160 private void buttonOpen_Click(object sender, EventArgs e)
165 iDisplay.RequestPowerSupplyStatus();
170 toolStripStatusLabelConnect.Text = "Connection error";
175 private void buttonClose_Click(object sender, EventArgs e)
181 private void buttonClear_Click(object sender, EventArgs e)
184 iDisplay.SwapBuffers();
187 private void buttonFill_Click(object sender, EventArgs e)
190 iDisplay.SwapBuffers();
193 private void trackBarBrightness_Scroll(object sender, EventArgs e)
195 Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value;
196 Properties.Settings.Default.Save();
197 iDisplay.SetBrightness(trackBarBrightness.Value);
201 private void UpdateStatus()
203 if (iDisplay.IsOpen())
205 buttonFill.Enabled = true;
206 buttonClear.Enabled = true;
207 buttonOpen.Enabled = false;
208 buttonClose.Enabled = true;
209 trackBarBrightness.Enabled = true;
210 trackBarBrightness.Minimum = iDisplay.MinBrightness();
211 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
212 trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
213 trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
214 trackBarBrightness.SmallChange = 1;
215 iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness);
217 toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
218 //+ " - " + iDisplay.SerialNumber();
222 buttonFill.Enabled = false;
223 buttonClear.Enabled = false;
224 buttonOpen.Enabled = true;
225 buttonClose.Enabled = false;
226 trackBarBrightness.Enabled = false;
227 toolStripStatusLabelConnect.Text = "Disconnected";
233 private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
235 tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
236 Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
237 Properties.Settings.Default.Save();
240 private void checkBoxConnectOnStartup_CheckedChanged(object sender, EventArgs e)
242 Properties.Settings.Default.DisplayConnectOnStartup = checkBoxConnectOnStartup.Checked;
243 Properties.Settings.Default.Save();