Note that there are some explanatory texts on larger screens.

plurals
  1. POC# How to setup presets with a context menu using windows forms?
    primarykey
    data
    text
    <p>I am trying to do something new in my learning of C#. I recently posted a similar question to setting up and populating a context menu directly. Now that I have that done, I find myself stuck getting the execution I need. </p> <p>I am creating a quick access list that is user defined. It is simply a name and IP Address. </p> <p>I am populating the list from an xml docmuent and adding to the context menu by:</p> <pre><code>ToolStripMenuItem.DropDownItems.Add(string name, image, eventargs onClick) </code></pre> <p>Where I am stuck is trying to figure out how to tell the click event what IP to use. I know in a method argument I could pass the IP address by adding another argument to the function such as:</p> <pre><code>doSomething("Hello World"); void doSomething(cmd) { messageBox.Show(cmd); } </code></pre> <p>How do get my variable menu choice to indicate the right IP address to the name? I assume if I can get the right IP used then I can use the same method to utilize the password as well. so my code looks like:</p> <pre><code> private void addToolStripMenuItem_Click(object sender, EventArgs e) { ... foreach(xml node in xml doc) { Room r = new Room(); r.Name =xNode.SelectSingleNode("Name").InnerText; r.IP = xNode.SelectSingleNode("IP").InnerText; r.passwrd=xNode.SelectSingleNode("Pass").InnerText; locations.add(r); presetsToolStripMenuItem.DropDownItems.Add(r.Name, null, disp); } } void disp(object sender, EventArgs e) { MessageBox.Show(r.Name's IP address); MessageBox.Show(r.Name's password); } </code></pre> <p>I am not against using another means of doing this. This was just what I could find that appeared to be the most simple. I just want to make sure it remains simple and the context menu/list is populated from an xml document. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload