Fixing issues with render when app is minimized.
1.1 --- a/MainForm.Designer.cs Sat Jul 12 13:13:17 2014 +0200
1.2 +++ b/MainForm.Designer.cs Sat Jul 12 22:18:34 2014 +0200
1.3 @@ -49,9 +49,9 @@
1.4 this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel();
1.5 this.panelDisplay = new System.Windows.Forms.Panel();
1.6 this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
1.7 + this.checkBoxConnectOnStartup = new System.Windows.Forms.CheckBox();
1.8 this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.9 this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.10 - this.checkBoxConnectOnStartup = new System.Windows.Forms.CheckBox();
1.11 this.tabControl.SuspendLayout();
1.12 this.tabPageDisplay.SuspendLayout();
1.13 ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
1.14 @@ -291,42 +291,33 @@
1.15 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.16 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.17 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.18 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.19 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.20 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.21 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.22 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.23 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.24 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.25 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.26 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.27 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.28 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.29 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.30 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.31 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.32 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.33 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.34 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.35 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.36 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.37 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.38 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.39 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.40 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.41 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
1.42 this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
1.43 this.tableLayoutPanel.TabIndex = 5;
1.44 //
1.45 - // marqueeLabelTop
1.46 - //
1.47 - this.marqueeLabelTop.AutoEllipsis = true;
1.48 - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.49 - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.50 - this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
1.51 - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.52 - this.marqueeLabelTop.Name = "marqueeLabelTop";
1.53 - this.marqueeLabelTop.OwnTimer = false;
1.54 - this.marqueeLabelTop.PixelsPerSecond = 64;
1.55 - this.marqueeLabelTop.Separator = "|";
1.56 - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 1);
1.57 - this.marqueeLabelTop.TabIndex = 2;
1.58 - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.59 - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.60 - this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.61 - //
1.62 - // marqueeLabelBottom
1.63 - //
1.64 - this.marqueeLabelBottom.AutoEllipsis = true;
1.65 - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.66 - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -19);
1.67 - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.68 - this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.69 - this.marqueeLabelBottom.OwnTimer = false;
1.70 - this.marqueeLabelBottom.PixelsPerSecond = 64;
1.71 - this.marqueeLabelBottom.Separator = null;
1.72 - this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
1.73 - this.marqueeLabelBottom.TabIndex = 3;
1.74 - this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.75 - this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.76 - this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.77 - //
1.78 // checkBoxConnectOnStartup
1.79 //
1.80 this.checkBoxConnectOnStartup.AutoSize = true;
1.81 @@ -338,6 +329,39 @@
1.82 this.checkBoxConnectOnStartup.UseVisualStyleBackColor = true;
1.83 this.checkBoxConnectOnStartup.CheckedChanged += new System.EventHandler(this.checkBoxConnectOnStartup_CheckedChanged);
1.84 //
1.85 + // marqueeLabelTop
1.86 + //
1.87 + this.marqueeLabelTop.AutoEllipsis = true;
1.88 + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.89 + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.90 + this.marqueeLabelTop.Location = new System.Drawing.Point(1, -901);
1.91 + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.92 + this.marqueeLabelTop.Name = "marqueeLabelTop";
1.93 + this.marqueeLabelTop.OwnTimer = false;
1.94 + this.marqueeLabelTop.PixelsPerSecond = 64;
1.95 + this.marqueeLabelTop.Separator = "|";
1.96 + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20);
1.97 + this.marqueeLabelTop.TabIndex = 2;
1.98 + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.99 + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.100 + this.marqueeLabelTop.UseCompatibleTextRendering = true;
1.101 + //
1.102 + // marqueeLabelBottom
1.103 + //
1.104 + this.marqueeLabelBottom.AutoEllipsis = true;
1.105 + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.106 + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -481);
1.107 + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.108 + this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.109 + this.marqueeLabelBottom.OwnTimer = false;
1.110 + this.marqueeLabelBottom.PixelsPerSecond = 64;
1.111 + this.marqueeLabelBottom.Separator = null;
1.112 + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20);
1.113 + this.marqueeLabelBottom.TabIndex = 3;
1.114 + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
1.115 + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.116 + this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.117 + //
1.118 // MainForm
1.119 //
1.120 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.121 @@ -349,6 +373,7 @@
1.122 this.Name = "MainForm";
1.123 this.Text = "Sharp Display Manager";
1.124 this.Load += new System.EventHandler(this.MainForm_Load);
1.125 + this.Resize += new System.EventHandler(this.MainForm_Resize);
1.126 this.tabControl.ResumeLayout(false);
1.127 this.tabPageDisplay.ResumeLayout(false);
1.128 this.tabPageDisplay.PerformLayout();
2.1 --- a/MainForm.cs Sat Jul 12 13:13:17 2014 +0200
2.2 +++ b/MainForm.cs Sat Jul 12 22:18:34 2014 +0200
2.3 @@ -7,7 +7,10 @@
2.4 using System.Text;
2.5 using System.Threading.Tasks;
2.6 using System.Windows.Forms;
2.7 +using System.IO;
2.8 using CodeProject.Dialog;
2.9 +using System.Drawing.Imaging;
2.10 +
2.11
2.12 namespace SharpDisplayManager
2.13 {
2.14 @@ -15,6 +18,8 @@
2.15 {
2.16 DateTime LastTickTime;
2.17 Display iDisplay;
2.18 + System.Drawing.Bitmap iBmp;
2.19 + bool iCreateBitmap; //Workaround render to bitmap issues when minimized
2.20
2.21 public MainForm()
2.22 {
2.23 @@ -31,6 +36,9 @@
2.24 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
2.25 //
2.26 tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
2.27 + //We have a bug when drawing minimized and reusing our bitmap
2.28 + iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
2.29 + iCreateBitmap = false;
2.30 }
2.31
2.32 private void MainForm_Load(object sender, EventArgs e)
2.33 @@ -80,7 +88,22 @@
2.34 {
2.35 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
2.36 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
2.37 - bmp.Save("c:\\capture.png");
2.38 + //Bitmap bmpToSave = new Bitmap(bmp);
2.39 + bmp.Save("D:\\capture.png");
2.40 +
2.41 + /*
2.42 + string outputFileName = "d:\\capture.png";
2.43 + using (MemoryStream memory = new MemoryStream())
2.44 + {
2.45 + using (FileStream fs = new FileStream(outputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
2.46 + {
2.47 + bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
2.48 + byte[] bytes = memory.ToArray();
2.49 + fs.Write(bytes, 0, bytes.Length);
2.50 + }
2.51 + }
2.52 + */
2.53 +
2.54 }
2.55
2.56 private void CheckForRequestResults()
2.57 @@ -117,7 +140,7 @@
2.58 }
2.59
2.60 private void timer_Tick(object sender, EventArgs e)
2.61 - {
2.62 + {
2.63 //Update our animations
2.64 DateTime NewTickTime = DateTime.Now;
2.65
2.66 @@ -129,19 +152,27 @@
2.67 {
2.68 CheckForRequestResults();
2.69
2.70 - //Draw to bitmap
2.71 - System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
2.72 - tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
2.73 + //Draw to bitmap
2.74 + if (iCreateBitmap)
2.75 + {
2.76 + iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
2.77 + }
2.78 + tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
2.79 + //iBmp.Save("D:\\capture.png");
2.80 +
2.81 + //iBmp.
2.82 +
2.83 //Send it to our display
2.84 - for (int i = 0; i < bmp.Width; i++)
2.85 + for (int i = 0; i < iBmp.Width; i++)
2.86 {
2.87 - for (int j = 0; j < bmp.Height; j++)
2.88 + for (int j = 0; j < iBmp.Height; j++)
2.89 {
2.90 unchecked
2.91 {
2.92 - uint color=(uint)bmp.GetPixel(i, j).ToArgb();
2.93 - //(checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000)
2.94 - iDisplay.SetPixel(i, j, Convert.ToInt32(color != 0xFFFFFFFF));
2.95 + uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
2.96 + //For some reason when the app is minimized in the task bar only the alpha of our color is set.
2.97 + //Thus that strange test for rendering to work both when the app is in the task bar and when it isn't.
2.98 + iDisplay.SetPixel(i, j, Convert.ToInt32(!(color != 0xFF000000)));
2.99 }
2.100 }
2.101 }
2.102 @@ -243,5 +274,15 @@
2.103 Properties.Settings.Default.Save();
2.104 }
2.105
2.106 + private void MainForm_Resize(object sender, EventArgs e)
2.107 + {
2.108 + if (WindowState == FormWindowState.Minimized)
2.109 + {
2.110 + // Do some stuff
2.111 + //iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
2.112 + iCreateBitmap = true;
2.113 + }
2.114 + }
2.115 +
2.116 }
2.117 }