diff --git a/VAR.Toolbox/UI/FrmIPScan.Designer.cs b/VAR.Toolbox/UI/FrmIPScan.Designer.cs index 6992186..2b0246c 100644 --- a/VAR.Toolbox/UI/FrmIPScan.Designer.cs +++ b/VAR.Toolbox/UI/FrmIPScan.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - this.lsvResult = new System.Windows.Forms.ListBox(); + this.ctrOutput = new VAR.Toolbox.Controls.CtrOutput(); this.btnScan = new System.Windows.Forms.Button(); this.lblStatus = new System.Windows.Forms.Label(); this.btnStop = new System.Windows.Forms.Button(); @@ -37,15 +37,14 @@ // // lsvResult // - this.lsvResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.ctrOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.lsvResult.FormattingEnabled = true; - this.lsvResult.Location = new System.Drawing.Point(9, 59); - this.lsvResult.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.lsvResult.Name = "lsvResult"; - this.lsvResult.Size = new System.Drawing.Size(350, 238); - this.lsvResult.TabIndex = 0; + this.ctrOutput.Location = new System.Drawing.Point(9, 59); + this.ctrOutput.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ctrOutput.Name = "lsvResult"; + this.ctrOutput.Size = new System.Drawing.Size(350, 238); + this.ctrOutput.TabIndex = 0; // // btnScan // @@ -96,7 +95,7 @@ this.Controls.Add(this.btnStop); this.Controls.Add(this.lblStatus); this.Controls.Add(this.btnScan); - this.Controls.Add(this.lsvResult); + this.Controls.Add(this.ctrOutput); this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Name = "FrmIPScan"; this.Text = "IPScan"; @@ -107,7 +106,7 @@ #endregion - private System.Windows.Forms.ListBox lsvResult; + private VAR.Toolbox.Controls.CtrOutput ctrOutput; private System.Windows.Forms.Button btnScan; private System.Windows.Forms.Label lblStatus; private System.Windows.Forms.Button btnStop; diff --git a/VAR.Toolbox/UI/FrmIPScan.cs b/VAR.Toolbox/UI/FrmIPScan.cs index d1e0164..f528aaa 100644 --- a/VAR.Toolbox/UI/FrmIPScan.cs +++ b/VAR.Toolbox/UI/FrmIPScan.cs @@ -12,12 +12,19 @@ namespace VAR.Toolbox.UI public FrmIPScan() { InitializeComponent(); + Disposed += FrmIPScan_Disposed; PrintStatus("Idle"); } + private void FrmIPScan_Disposed(object sender, EventArgs e) + { + running = false; + } + private void PrintStatus(string status) { + if (lblStatus.IsDisposed) { return; } if (lblStatus.InvokeRequired) { lblStatus.Invoke((MethodInvoker)(() => { lblStatus.Text = string.Format("Status: {0}", status); })); @@ -28,22 +35,10 @@ namespace VAR.Toolbox.UI Application.DoEvents(); } } - - private void ResultsAddLine(string line) - { - if (lsvResult.InvokeRequired) - { - lsvResult.Invoke((MethodInvoker)(() => { lsvResult.Items.Add(line); })); - } - else - { - lsvResult.Items.Add(line); - Application.DoEvents(); - } - } - + private void Control_SetEnabled(Control ctrl, bool enabled) { + if (ctrl.IsDisposed) { return; } if (ctrl.InvokeRequired) { ctrl.Invoke((MethodInvoker)(() => { ctrl.Enabled = enabled; })); @@ -72,7 +67,7 @@ namespace VAR.Toolbox.UI { Control_SetEnabled(btnScan, false); running = true; - ResultsAddLine(string.Format("IPScan started at {0}", DateTime.UtcNow.ToString("s"))); + ctrOutput.AddLine(string.Format("IPScan started at {0}", DateTime.UtcNow.ToString("s"))); for (int i = 1; i < 255 && running; i++) { string ip = ipBase + i.ToString(); @@ -88,12 +83,12 @@ namespace VAR.Toolbox.UI name = hostEntry.HostName; } catch (SocketException) { } - ResultsAddLine(string.Format("{0} ({1}) is up: ({2} ms)", ip, name, pingReply.RoundtripTime)); + ctrOutput.AddLine(string.Format("{0} ({1}) is up: ({2} ms)", ip, name, pingReply.RoundtripTime)); } Application.DoEvents(); } PrintStatus("Idle"); - ResultsAddLine(string.Format("IPScan ended at {0}", DateTime.UtcNow.ToString("s"))); + ctrOutput.AddLine(string.Format("IPScan ended at {0}", DateTime.UtcNow.ToString("s"))); Control_SetEnabled(btnScan, true); }