Context Menu in Win Forms

May 12, 2008

Problem: How to add a context menu to a control and then add an event handler to it?

Solution:
ContextMenu refreshPopUp = new ContextMenu();
refreshPopUp.MenuItems.Add(“[context menu text]“, new EventHandler([method name]));
refreshPopUp.Show([control], new System.Drawing.Point(X, Y));

// Write the code for the event handler

private void methodName(object sender, EventArgs e)
{
     do something;
}

Danish Khan

Ramp Technology

Entry Filed under: Win Form. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

May 2008
M T W T F S S
    Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Most Recent Posts