Home>
I am currently trying to handle the same event handler for multiple richTextBox controls.
However, you do not know which control caused the event.

When right-clicking a rich text box
I am coding to call the context menu and process it.

Because it is called in the order of [Rich Text Box] → [Context Menu] → [Process],
I don't think it can be confirmed with the following code.

private void hoge_contextMenuStrip_Opening (object sender, CancelEventArgs e)
        {
            Console.WriteLine ((sender as ContextMenuStrip) .Name);
        }
c#
  • Answer # 1

    I stopped using the debugger and stopped at the beginning of this event, and then looked into the contents ofsenderand thought it would not be obvious.
    (I often search this way)

    Right-click on any control,
    There was a lot in itself.
    It seems to be taken with((ContextMenuStrip) sender) .SourceControl.Name.

  • Answer # 2

    Can't you identify by the name of the originating control?

Trends