void LineBeginVisualInstruction_Click(object sender, MouseEventArgs e) { if (!e.Button.Equals(MouseButtons.Right)) { return; } VisualInstructionUserControl visualInstruction = (VisualInstructionUserControl)sender; if (visualInstruction.OpCode == OperationCode.LineBegin) { ladderForm.mnuAddressing.Enabled = false; ladderForm.mnuInsertLadderLine.Enabled = true; ladderForm.mnuExtendParallelBranchAbove.Enabled = false; ladderForm.mnuExtendParallelBranchAbove.Visible = false; ladderForm.mnuExtendParallelBranchBelow.Enabled = false; ladderForm.mnuExtendParallelBranchBelow.Visible = false; ladderForm.mnuContextAtInstruction.Show(visualInstruction.PointToScreen(e.Location)); } }
void VisualInstruction_Click(object sender, MouseEventArgs e) { if (!e.Button.Equals(MouseButtons.Right)) { return; } VisualInstructionUserControl visualInstruction = (VisualInstructionUserControl)sender; OperationCode opCode = visualInstruction.OpCode; if (opCode != OperationCode.LineBegin) { ladderForm.mnuInsertLadderLine.Enabled = false; ladderForm.mnuToggleBit.Enabled = false; if (opCode == OperationCode.ParallelBranchBegin || opCode == OperationCode.ParallelBranchEnd || opCode == OperationCode.ParallelBranchNext) { ladderForm.mnuAddressing.Enabled = false; ladderForm.mnuAddressing.Visible = false; ladderForm.mnuExtendParallelBranchAbove.Enabled = true; ladderForm.mnuExtendParallelBranchAbove.Visible = true; ladderForm.mnuExtendParallelBranchBelow.Enabled = true; ladderForm.mnuExtendParallelBranchBelow.Visible = true; } else { ladderForm.mnuAddressing.Enabled = true; ladderForm.mnuAddressing.Visible = true; if (visualInstruction.IsAllOperandsOk()) { ladderForm.mnuToggleBit.Enabled = true; } else { ladderForm.mnuToggleBit.Enabled = false; } ProjectForm projectForm = ladderForm.projectForm; TreeNode addressingNode = projectForm.tvnProjectTree.Nodes["tvnProjectNode"].Nodes["tvnAddressingNode"]; foreach (TreeNode eachAddressTypeNode in addressingNode.Nodes) { ToolStripMenuItem menu = null; switch (eachAddressTypeNode.Text) { case "Memories": menu = ladderForm.mnuMemory; break; case "Timer": menu = ladderForm.mnuTimer; break; case "Counter": menu = ladderForm.mnuCounter; break; case "Input": menu = ladderForm.mnuInput; break; case "Output": menu = ladderForm.mnuOutput; break; } Address address = null; if (visualInstruction.IsAllOperandsOk()) { Object obj = visualInstruction.GetOperand(0); if (obj is Address) { address = (Address)obj; } } menu.DropDownItems.Clear(); foreach (TreeNode eachAddressNode in eachAddressTypeNode.Nodes) { menu.DropDownItems.Add(eachAddressNode.Text); if (address != null) { if (address.GetName() == eachAddressNode.Text) { menu.DropDownItems[menu.DropDownItems.Count - 1].Select(); } } menu.DropDownItems[menu.DropDownItems.Count - 1].Name = eachAddressNode.Text; menu.DropDownItems[menu.DropDownItems.Count - 1].Tag = eachAddressNode.Tag; menu.DropDownItems[menu.DropDownItems.Count - 1].Click += new EventHandler(MenuContextAddress_Click); } } } } ladderForm.mnuContextAtInstruction.Show(visualInstruction.PointToScreen(e.Location)); }