diff --git a/EduNetworkBuilder/IPAddressEntry.cs b/EduNetworkBuilder/IPAddressEntry.cs index 7d8aae6..70bf153 100644 --- a/EduNetworkBuilder/IPAddressEntry.cs +++ b/EduNetworkBuilder/IPAddressEntry.cs @@ -17,13 +17,24 @@ namespace EduNetworkBuilder { NB_IPAddress WhatToEdit; NB_IPAddress DHCPInterface=null; - bool WellDone = true; + bool WellDone = false; NetworkDevice ParentDevice = null; Point StartLocation = new Point (50,50); NB_IPAddress SavedIPAddress = null; ToolTip myTooltip = new ToolTip(); + //variable to hold true if the for is closing + private bool isFormClosing = false; + // Contant for the close message + private const int WM_CLOSE = 16; + //override the WndProc msg to trap the WM_CLOSE message + protected override void WndProc(ref Message m) + { + if (m.Msg == WM_CLOSE) + isFormClosing = true; + base.WndProc(ref m); + } public IPAddressEntry(NB_IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm, bool JustPinging=false) { @@ -152,6 +163,7 @@ namespace EduNetworkBuilder WhatToEdit.Reparse(tbIPAddress.Text, tbNetmask.Text, tbGateway.Text); Network myNet = NB.GetNetwork(); myNet.StoreLastIP(WhatToEdit); + WellDone = true; Close(); } @@ -189,13 +201,12 @@ namespace EduNetworkBuilder if(SavedIPAddress != null) WhatToEdit.Reparse(SavedIPAddress.GetIPString, SavedIPAddress.GetMaskString, SavedIPAddress.GetGateway.ToIpString()); UpdateFieldsFromAddress(); - WellDone = false; Close(); } private void tbGateway_Validating(object sender, CancelEventArgs e) { - if (!WellDone) return; + if (isFormClosing) return; Network mynet = NB.GetNetwork(); if (ParentDevice != null) @@ -224,7 +235,7 @@ namespace EduNetworkBuilder private void tbNetmask_Validating(object sender, CancelEventArgs e) { - if (!WellDone) return; + if (isFormClosing) return; UInt32 taddress = tbNetmask.Text.ParseIp(); tbNetmask.Text = taddress.ToIpString(); @@ -241,7 +252,7 @@ namespace EduNetworkBuilder private void tbIPAddress_Validating(object sender, CancelEventArgs e) { - if (!WellDone) return; + if (isFormClosing) return; UInt32 taddress; Network mynet = NB.GetNetwork();