Allow ping/arp/traceroute to cancel by 'x'
WellDone ought to default to "false" so that canceling the form does not return a true. However, that then means that the validating (particularly for DHCP) needs to be handled differently. Otherwise validation would ONLY occur when you press OK. (Not a terrible thing, but also not ideal.) In any case, this is a solution I found on the internet. It seems to work nicely. Validating still runs unless the form is closing (via ESC, Cancel, or X), including when moving from textbox to textbox, or tabbing to OK. I think this also solves a lingering problem where DHCP couldn't X out without attempting to validate. So it feels like an all-around winner. Step to reproduce: Level0 ping test 1.) on net_switch0, try to ping pc0. -tab through and notice that pc0 resolves to 192.168.1.2 on OK button. 2.) close with form window using X -notice that the ping happens anyway. Same is true for arp and traceroute.
This commit is contained in:
parent
5d06bfd8f3
commit
93f0c6e4a3
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user