right-click delete a link

This commit is contained in:
Tim Young 2018-02-16 17:48:08 +00:00
parent f7b82d38c9
commit 620ffa1bc2

View File

@ -932,6 +932,27 @@ namespace EduNetworkBuilder
}
}
private void pbNetworkView_RightMouseUponLink(NetworkLink LinkReleasedOn, MouseEventArgs e)
{
if (LinkReleasedOn == null) return;
if (pbNetworkView.ContextMenuStrip == null)
{
pbNetworkView.ContextMenuStrip = new ContextMenuStrip();
}
pbNetworkView.ContextMenuStrip.Items.Clear();
int index=0;
//We need to make sure the item is not critical before we delete it.
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
pbNetworkView.ContextMenuStrip.Items[index].Tag = LinkReleasedOn;
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_RemoveNetLink_Click;
pbNetworkView.ContextMenuStrip.Visible = true;
pbNetworkView.ContextMenuStrip.Show(Cursor.Position);
}
private void pbNetworkView_Hide_Click(object sender, EventArgs e)
{
if (ItemClickedOn != null)
@ -1064,6 +1085,21 @@ namespace EduNetworkBuilder
}
private void pbNetworkView_RemoveNetLink_Click(object sender, EventArgs e)
{
ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null)
{
NetworkLink NL = (NetworkLink)thing.Tag;
myNetwork.RemoveComponent(NL);
}
myNetwork.TestForCompletion(true);
pbNetworkView.Update();
UpdateVisuals();
}
private void pbNetworkView_DHCPRequest_Click(object sender, EventArgs e)
{
ItemClickedOn.DHCPRequestFromHere();
@ -1245,6 +1281,15 @@ namespace EduNetworkBuilder
TimeSpan duration;
duration = DateTime.Now - LastClick;
if(ReleasedOnLink != null && e.Button == MouseButtons.Right)
{
//Right-click on a line. Make a special context menu for that.
// delete
// edit
pbNetworkView_RightMouseUponLink(ReleasedOnLink, e);
return; //We do not do the rest of this...
}
//Track size of area for the click/drag
int sx;
int sy;
@ -1418,7 +1463,8 @@ namespace EduNetworkBuilder
ClickedImageLocation = e.Location;
//See if we have clicked on something
ItemClickedOn = myNetwork.ItemAtPosition(location);
MouseIsDown = true;
if(e.Button == MouseButtons.Left)
MouseIsDown = true;
LastMouseDown = DateTime.UtcNow;
//Make a duplicate of the old background image.
LastBackgroundImage = new Bitmap(pbNetworkView.BackgroundImage);