Fixing string measurement issues. Font dialog now properly initialized with
loaded font.
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;
29 checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
32 private void buttonFont_Click(object sender, EventArgs e)
34 //fontDialog.ShowColor = true;
35 //fontDialog.ShowApply = true;
36 fontDialog.ShowEffects = true;
37 fontDialog.Font = marqueeLabelTop.Font;
38 //fontDialog.ShowHelp = true;
40 //fontDlg.MaxSize = 40;
41 //fontDlg.MinSize = 22;
43 //fontDialog.Parent = this;
44 //fontDialog.StartPosition = FormStartPosition.CenterParent;
46 //DlgBox.ShowDialog(fontDialog);
48 //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
49 if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
52 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
54 //MessageBox.Show("Ok");
55 marqueeLabelTop.Font = fontDialog.Font;
56 marqueeLabelBottom.Font = fontDialog.Font;
57 Properties.Settings.Default.DisplayFont = fontDialog.Font;
58 Properties.Settings.Default.Save();
59 //label1.Font = fontDlg.Font;
60 //textBox1.BackColor = fontDlg.Color;
61 //label1.ForeColor = fontDlg.Color;
65 private void buttonCapture_Click(object sender, EventArgs e)
67 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
68 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
69 bmp.Save("c:\\capture.png");
72 private void timer_Tick(object sender, EventArgs e)
74 //Update our animations
75 DateTime NewTickTime = DateTime.Now;
77 marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
78 marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
81 if (iDisplay.IsOpen())
84 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
85 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
86 //Send it to our display
87 for (int i = 0; i < bmp.Width; i++)
89 for (int j = 0; j < bmp.Height; j++)
93 uint color=(uint)bmp.GetPixel(i, j).ToArgb();
94 iDisplay.SetPixel(i, j, Convert.ToInt32((checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000)));
99 iDisplay.SwapBuffers();
103 //Compute instant FPS
104 toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
106 LastTickTime = NewTickTime;
110 private void buttonOpen_Click(object sender, EventArgs e)
119 toolStripStatusLabelConnect.Text = "Connection error";
124 private void buttonClose_Click(object sender, EventArgs e)
130 private void buttonClear_Click(object sender, EventArgs e)
133 iDisplay.SwapBuffers();
136 private void buttonFill_Click(object sender, EventArgs e)
139 iDisplay.SwapBuffers();
142 private void trackBarBrightness_Scroll(object sender, EventArgs e)
144 Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value;
145 Properties.Settings.Default.Save();
146 iDisplay.SetBrightness(trackBarBrightness.Value);
150 private void UpdateStatus()
152 if (iDisplay.IsOpen())
154 buttonFill.Enabled = true;
155 buttonClear.Enabled = true;
156 buttonOpen.Enabled = false;
157 buttonClose.Enabled = true;
158 trackBarBrightness.Enabled = true;
159 trackBarBrightness.Minimum = iDisplay.MinBrightness();
160 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
161 trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
162 trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
163 trackBarBrightness.SmallChange = 1;
164 iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness);
166 toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
167 //+ " - " + iDisplay.SerialNumber();
171 buttonFill.Enabled = false;
172 buttonClear.Enabled = false;
173 buttonOpen.Enabled = true;
174 buttonClose.Enabled = false;
175 trackBarBrightness.Enabled = false;
176 toolStripStatusLabelConnect.Text = "Disconnected";
180 private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
182 Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
183 Properties.Settings.Default.Save();