TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Andy Webster
NA
117
0
Reference to a window control from context menu item click event handler
Mar 2 2010 5:31 AM
Can anyone tell me how I can get a reference to the host control of a context menu from within the click event handler for a ToolStripMenuItem.
I am trying to create a generic context menu for a label control that allows the user to copy the label text to the clipboard. My current code is specific to the label:
private void copyTextToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
SetClipboardText(myLabel.Text);
}
catch (Exception ex)
{
}
}
The sender is a ToolStripMenuItem so I can get a reference to it by casting the sender. How can I get a reference to the control, that is the label, which the menu was dropped down from?
private void copyTextToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
Label myLabel = // WHAT GOES HERE ?
SetClipboardText(myLabel.Text);
}
catch (Exception ex)
{
}
}
Thanks for any help you can give.
Reply
Answers (
8
)
substract the values in dialgrid in vb.net
how to Representation data basein c