1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
該For a ContextMenuStrip答案為SO問題的部分確定哪些控制的ContextMenuStrip被使用上 幾乎回答我的問題。
但是,在我的情況下,我想處理ContextMenuStrip項(xiàng)目右鍵單擊并在更改時(shí)訪問ContextMenuStrip項(xiàng)目,因此我的代碼使用項(xiàng)目事件方法而不是項(xiàng)目事件方法。因此,我需要將發(fā)件人強(qiáng)制轉(zhuǎn)換為 a而不是 。除此之外,我使用SO 問題中的部分答案確定在我的事件方法中使用了 ContextMenuStrip 的哪個(gè)控件:CheckStateCheckStateContextMenuStrip_CheckStateChangedContextMenuStrip_ClickToolStripMenuItemToolStripItemFor a ContextMenuStripDocumentActionToolStripMenuItem_CheckStateChanged
private void DocumentActionToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
{
Control treeNodeControl;
ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender;
// if the ToolStripMenuItem item is owned by a ContextMenuStrip ...
if (toolStripMenuItem.Owner is ContextMenuStrip contextMenuStrip)
{
// Get the TreeNode that is displaying this context menu
treeNodeControl = contextMenuStrip.SourceControl;
if (toolStripMenuItem.CheckState == CheckState.Checked)
{
//Do something with treeNodeControl.SelectedNode treeView node
}
}
}
- 1 回答
- 0 關(guān)注
- 176 瀏覽
添加回答
舉報(bào)