1

I am attempting to build a TCP based controller for the servers and VMs in my house, I want each server to have a dedicated port so I can easily know which is which as there are quite a few HyperV instances running. I have designed the basic control server to my liking, but I am having trouble with ContextMenuStrips.

I have 18 servers or VMs I want to be able to manage through my program (Main purpose is running PowerShell scripts or other mundane tasks on all machines at once) but I cannot figure this part out. Each of the port listings exist within a panel, the panel contains a PictureBox and a Label. The ContextMenu Strip shown there is enabled on each of the panels which wrap the other items. How would I be able to find which one of the panels I right clicked on to update? Would I need to create a ContextMenu per panel, is just looking at pointer position at the right click action and having some lists that define boundaries the best way or am I just unaware of a better way to do this?

What I have

Tyson
  • 45
  • 9
  • 2
    [Get SourceControl Of DropDownMenu](https://stackoverflow.com/a/53263702/7444103). Set the Panel's child label text. – Jimi Nov 26 '19 at 06:58
  • I ran into a snag while attempting to implement the test code you provided on that post. https://i.imgur.com/1h80Qzr.png I did create the Opened event handler for the menu strip https://i.imgur.com/tzFazBQ.png I half understand what is happening with the code you provided, gonna read the documentation and hopefully find some more understanding – Tyson Nov 26 '19 at 07:10
  • Did you just create it or did you also subscribed to it? If you set a breakpoint there, does it get hit? – Jimi Nov 26 '19 at 07:14
  • The break point does get hit but I am not familiar with what you mean by subscribe to it – Tyson Nov 26 '19 at 07:16
  • If setting a breakpoint stops the code execution inside the handler (the `contextMenuStrip1_Opened` handler), then the event is subscribed. What is `(sender as ContextMenuStrip).SourceControl` at that point (the `SourceControl` value)? – Jimi Nov 26 '19 at 07:18
  • It holds "{System.Windows.Forms.Panel, BorderStyle: System.Windows.Forms.BorderStyle.None}" when it hit the breakpoint – Tyson Nov 26 '19 at 07:20
  • Check twice what you have implemented of the code i linked. Since `SourceControl` is a Panel control, as you have also confirmed, it cannot be null at that point, unless it's been set to null elsewhere. See that you don't have more then one ContextMenuStrip. – Jimi Nov 26 '19 at 07:29
  • On a whim I commented out the setting to null on close and now it is working... I'm a bit confused but thank you very much :D I will find a way to fully implement this to my needs. You have yourself a wonderful day Jimi – Tyson Nov 26 '19 at 07:33

0 Answers0