# HG changeset patch # User sl # Date 1405196314 -7200 # Node ID d1fa9de444b0ff93f6e8c2a4b215b65415c8c642 # Parent 745d9ee1a2c0346219b18f08cf91e54955833c6a Fixing issues with render when app is minimized. diff -r 745d9ee1a2c0 -r d1fa9de444b0 MainForm.Designer.cs --- a/MainForm.Designer.cs Sat Jul 12 13:13:17 2014 +0200 +++ b/MainForm.Designer.cs Sat Jul 12 22:18:34 2014 +0200 @@ -49,9 +49,9 @@ this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel(); this.panelDisplay = new System.Windows.Forms.Panel(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.checkBoxConnectOnStartup = new System.Windows.Forms.CheckBox(); this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); - this.checkBoxConnectOnStartup = new System.Windows.Forms.CheckBox(); this.tabControl.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit(); @@ -291,42 +291,33 @@ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 5; // - // marqueeLabelTop - // - this.marqueeLabelTop.AutoEllipsis = true; - this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; - this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1); - this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelTop.Name = "marqueeLabelTop"; - this.marqueeLabelTop.OwnTimer = false; - this.marqueeLabelTop.PixelsPerSecond = 64; - this.marqueeLabelTop.Separator = "|"; - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 1); - this.marqueeLabelTop.TabIndex = 2; - this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; - this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabelTop.UseCompatibleTextRendering = true; - // - // marqueeLabelBottom - // - this.marqueeLabelBottom.AutoEllipsis = true; - this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -19); - this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); - this.marqueeLabelBottom.Name = "marqueeLabelBottom"; - this.marqueeLabelBottom.OwnTimer = false; - this.marqueeLabelBottom.PixelsPerSecond = 64; - this.marqueeLabelBottom.Separator = null; - this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20); - this.marqueeLabelBottom.TabIndex = 3; - this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; - this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.marqueeLabelBottom.UseCompatibleTextRendering = true; - // // checkBoxConnectOnStartup // this.checkBoxConnectOnStartup.AutoSize = true; @@ -338,6 +329,39 @@ this.checkBoxConnectOnStartup.UseVisualStyleBackColor = true; this.checkBoxConnectOnStartup.CheckedChanged += new System.EventHandler(this.checkBoxConnectOnStartup_CheckedChanged); // + // marqueeLabelTop + // + this.marqueeLabelTop.AutoEllipsis = true; + this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; + this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelTop.Location = new System.Drawing.Point(1, -901); + this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelTop.Name = "marqueeLabelTop"; + this.marqueeLabelTop.OwnTimer = false; + this.marqueeLabelTop.PixelsPerSecond = 64; + this.marqueeLabelTop.Separator = "|"; + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20); + this.marqueeLabelTop.TabIndex = 2; + this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; + this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelTop.UseCompatibleTextRendering = true; + // + // marqueeLabelBottom + // + this.marqueeLabelBottom.AutoEllipsis = true; + this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -481); + this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabelBottom.Name = "marqueeLabelBottom"; + this.marqueeLabelBottom.OwnTimer = false; + this.marqueeLabelBottom.PixelsPerSecond = 64; + this.marqueeLabelBottom.Separator = null; + this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 20); + this.marqueeLabelBottom.TabIndex = 3; + this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789"; + this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabelBottom.UseCompatibleTextRendering = true; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -349,6 +373,7 @@ this.Name = "MainForm"; this.Text = "Sharp Display Manager"; this.Load += new System.EventHandler(this.MainForm_Load); + this.Resize += new System.EventHandler(this.MainForm_Resize); this.tabControl.ResumeLayout(false); this.tabPageDisplay.ResumeLayout(false); this.tabPageDisplay.PerformLayout(); diff -r 745d9ee1a2c0 -r d1fa9de444b0 MainForm.cs --- a/MainForm.cs Sat Jul 12 13:13:17 2014 +0200 +++ b/MainForm.cs Sat Jul 12 22:18:34 2014 +0200 @@ -7,7 +7,10 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; using CodeProject.Dialog; +using System.Drawing.Imaging; + namespace SharpDisplayManager { @@ -15,6 +18,8 @@ { DateTime LastTickTime; Display iDisplay; + System.Drawing.Bitmap iBmp; + bool iCreateBitmap; //Workaround render to bitmap issues when minimized public MainForm() { @@ -31,6 +36,9 @@ checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; // tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); + //We have a bug when drawing minimized and reusing our bitmap + iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); + iCreateBitmap = false; } private void MainForm_Load(object sender, EventArgs e) @@ -80,7 +88,22 @@ { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); - bmp.Save("c:\\capture.png"); + //Bitmap bmpToSave = new Bitmap(bmp); + bmp.Save("D:\\capture.png"); + + /* + string outputFileName = "d:\\capture.png"; + using (MemoryStream memory = new MemoryStream()) + { + using (FileStream fs = new FileStream(outputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Png); + byte[] bytes = memory.ToArray(); + fs.Write(bytes, 0, bytes.Length); + } + } + */ + } private void CheckForRequestResults() @@ -117,7 +140,7 @@ } private void timer_Tick(object sender, EventArgs e) - { + { //Update our animations DateTime NewTickTime = DateTime.Now; @@ -129,19 +152,27 @@ { CheckForRequestResults(); - //Draw to bitmap - System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); - tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); + //Draw to bitmap + if (iCreateBitmap) + { + iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); + } + tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle); + //iBmp.Save("D:\\capture.png"); + + //iBmp. + //Send it to our display - for (int i = 0; i < bmp.Width; i++) + for (int i = 0; i < iBmp.Width; i++) { - for (int j = 0; j < bmp.Height; j++) + for (int j = 0; j < iBmp.Height; j++) { unchecked { - uint color=(uint)bmp.GetPixel(i, j).ToArgb(); - //(checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000) - iDisplay.SetPixel(i, j, Convert.ToInt32(color != 0xFFFFFFFF)); + uint color = (uint)iBmp.GetPixel(i, j).ToArgb(); + //For some reason when the app is minimized in the task bar only the alpha of our color is set. + //Thus that strange test for rendering to work both when the app is in the task bar and when it isn't. + iDisplay.SetPixel(i, j, Convert.ToInt32(!(color != 0xFF000000))); } } } @@ -243,5 +274,15 @@ Properties.Settings.Default.Save(); } + private void MainForm_Resize(object sender, EventArgs e) + { + if (WindowState == FormWindowState.Minimized) + { + // Do some stuff + //iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); + iCreateBitmap = true; + } + } + } }