Solved

Need to Programatically Find Controls With ContextMenuStrips Containing "Run" MenuItem, Then Initiate Addhandler Call to SubRoutine

Posted on 2014-01-16
1
243 Views
Last Modified: 2014-01-17
I am adding elements of each control's contextmenustrips using the code below

sender.Items.AddRange(New ToolStripItem() {ctmsview, ctmsrun, ctmsdelete})

where for example, the ctmsrun text is:

ctmsrun.Text = "Run"

If a user right clicks on a control's contextmenustrip and selects "Run", then the addhandler runs the ctmsrun routine.   Very important: once inside the ctmsrun routine, the source control's name is used to determine what to do.

Question is, what's the best way to pick off all the control's whose contextmenustrip have a "Run" menu item, and then fire the ctmsrun routine as if the user right clicked on sequential form controls (there is a defined sequence of the controls to be run, and that is known)?  

So the question is: Given many Form controls with contextmenustrips (not all controls have a contextmenustrip) what's the best way to identify those with a either "Run" as the text or ctmsrun used with the addhandler (to actually fire the subroutine).  

My guess is to just loop through all controls, identify which controls have a contextmenustrip, and then find out if there is a ctsmrun command or "Run" text in the menu item text?  The call ctmsrun somehow for that source control?

By the way, once inside the ctmsrun routine, I use the following to obtain the name of the parent control of the specific contextmenustrip that was right-clicked:  

 Dim myItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
 Dim cms As ContextMenuStrip = CType(myItem.Owner, ContextMenuStrip)
 cmssourcecontrolname = cms.Name

Open in new window

   

However, I need to find out what the menu items are within the contextmenustrip.
0
Comment
Question by:lep1
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39788546
The ContextMenuStrip has the Items property, which are the menu items.  You should be able to loop through the items to get what you need.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now