using System; using System.Windows.Forms; using Microsoft.Win32; using System.Drawing; public partial class DebugWindow : Form { private System.Windows.Forms.DataGridView TableView; private System.Windows.Forms.DataGridViewTextBoxColumn wName; private System.Windows.Forms.DataGridViewTextBoxColumn wValue; private System.Windows.Forms.DataGridViewTextBoxColumn wType; private System.Windows.Forms.DataGridViewTextBoxColumn wCount; public DebugWindow() { this.TableView = new System.Windows.Forms.DataGridView(); this.wName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.wValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.wType = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.wCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.TableView)).BeginInit(); this.SuspendLayout(); // // TableView // this.TableView.AllowUserToAddRows = false; this.TableView.AllowUserToDeleteRows = false; this.TableView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.TableView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.wName, this.wValue, this.wType, this.wCount }); this.TableView.Dock = System.Windows.Forms.DockStyle.Fill; this.TableView.ReadOnly = true; this.TableView.RowHeadersVisible = false; // // column Name // this.wName.HeaderText = "Name"; this.wName.ReadOnly = true; this.wName.Width = Settings.Default.wName; // // column Value // this.wValue.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.wValue.HeaderText = "Value"; this.wValue.ReadOnly = true; this.wValue.Width = Settings.Default.wValue; // // column Type // this.wType.HeaderText = "Type"; this.wType.ReadOnly = true; this.wType.Width = Settings.Default.wType; // // column Count // this.wCount.HeaderText = "Count"; this.wCount.ReadOnly = true; this.wCount.Width = Settings.Default.wCount; // // Form // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Controls.Add(this.TableView); this.Text = "Debug information window"; this.TopMost = true; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Debug_FormClosing); this.Load += new EventHandler(Debug_Load); this.Resize += new EventHandler(Debug_Resize_LocationChanged); this.LocationChanged += new EventHandler(Debug_Resize_LocationChanged); this.TableView.ColumnWidthChanged += new DataGridViewColumnEventHandler(TableView_ColumnWidthChanged); ((System.ComponentModel.ISupportInitialize)(this.TableView)).EndInit(); this.ResumeLayout(false); } void TableView_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { Settings.Default.wName = this.wName.Width; Settings.Default.wValue = this.wValue.Width; Settings.Default.wType = this.wType.Width; Settings.Default.wCount = this.wCount.Width; Settings.Default.Save(); } void Debug_Resize_LocationChanged(object sender, EventArgs e) { Settings.Default.WindowGeometry = GeometryToString(this); Settings.Default.Save(); } void Debug_Load(object sender, EventArgs e) { GeometryFromString(Settings.Default.WindowGeometry, this); } #region form position static Rectangle GetMaxBounds() { Rectangle bounds; int left_min, top_min, right_max, bottom_max; left_min = 0; top_min = 0; right_max = 0; bottom_max = 0; foreach (var screen in System.Windows.Forms.Screen.AllScreens) { bounds = screen.Bounds; left_min = Math.Min(left_min, bounds.Left); right_max = Math.Max(right_max, bounds.Right); top_min = Math.Min(top_min, bounds.Top); bottom_max = Math.Max(bottom_max, bounds.Bottom); } return new Rectangle(left_min, top_min, right_max - left_min, bottom_max - top_min); } static void GeometryFromString(string thisWindowGeometry, Form formIn) { if (string.IsNullOrEmpty(thisWindowGeometry) == true) { return; } string[] numbers = thisWindowGeometry.Split('|'); string windowString = numbers[4]; Point windowPoint = new Point(int.Parse(numbers[0]), int.Parse(numbers[1])); Size windowSize = new Size(int.Parse(numbers[2]), int.Parse(numbers[3])); Rectangle max = GetMaxBounds(); if (max.Contains(windowPoint)) { if (windowString == "Maximized") { formIn.Location = windowPoint; formIn.StartPosition = FormStartPosition.Manual; formIn.WindowState = FormWindowState.Maximized; } else if (windowString == "Normal") { formIn.Location = windowPoint; formIn.Size = windowSize; formIn.StartPosition = FormStartPosition.Manual; formIn.WindowState = FormWindowState.Normal; } } } static string GeometryToString(Form mainForm) { return mainForm.Location.X.ToString() + "|" + mainForm.Location.Y.ToString() + "|" + mainForm.Size.Width.ToString() + "|" + mainForm.Size.Height.ToString() + "|" + mainForm.WindowState.ToString(); } #endregion public void SetRow(string name, string value, string type, string count) { this.Show(); try { DataGridViewRow row0 = null; foreach (DataGridViewRow row in this.TableView.Rows) { if (row.Cells[0].Value.ToString() == name) { row0 = row; break; } } if (row0 == null) { TableView.Rows.Add(new string[] { name, value, type, count }); } else { row0.Cells[0].Value = name; row0.Cells[1].Value = value; row0.Cells[2].Value = type; row0.Cells[3].Value = count; } } catch { } } private void Debug_FormClosing(object sender, FormClosingEventArgs e) { var r = MessageBox.Show("Hide? Are You Sure?", "Debug information window", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (r == DialogResult.Cancel) e.Cancel = true; else if (r == DialogResult.No) e.Cancel = true; else if (r == DialogResult.Yes) { e.Cancel = true; this.Hide(); } } }