第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

有沒有辦法知道在左鍵單擊其 ContextMenuStrip 項(xiàng)目之一并且該項(xiàng)目

有沒有辦法知道在左鍵單擊其 ContextMenuStrip 項(xiàng)目之一并且該項(xiàng)目

C#
一只萌萌小番薯 2021-06-04 09:13:04
orhtej2 建議我的問題可能是確定在 ContextMenuStrip 上使用了什么控件。這幾乎是一個(gè)重復(fù),但我的場(chǎng)景有一個(gè)顯著差異。有關(guān)詳細(xì)信息,請(qǐng)參閱我修改后的問題和我的答案。請(qǐng)參閱下面的我的代碼。我的目標(biāo)是更清楚地確定在左鍵單擊其 ContextMenuItems 之一后右鍵單擊哪個(gè) TreeNode。現(xiàn)在,當(dāng)我右鍵單擊兩個(gè)子節(jié)點(diǎn)之一時(shí), 中的if語(yǔ)句TreeView1_NodeMouseClick會(huì)將單擊TreeNode的treeViewClickedNode TreeNode對(duì)象加載到全局對(duì)象中。然后,當(dāng)我左鍵單擊兩者之一時(shí)contextMenuStripChildNode ToolStripMenuItem,該DocumentActionToolStripMenuItem_CheckStateChanged方法被觸發(fā)。然后我可以檢查檢查狀態(tài)。如果它被選中,我可以對(duì)treeViewClickedNode TreeNode.我的問題:是否有一種更清晰的方法來確定在左鍵單擊其 ContextMenuStrip 項(xiàng)目之一后右鍵單擊哪個(gè) TreeNode,即,是否有辦法取消全局變量treeViewClickedNode?注意:我在設(shè)計(jì)器中所做的唯一一件事就是放置treeview1在 上Form1,將其??康紽orm1并將“treeview1”設(shè)置NodeMouseClick為TreeView1_NodeMouseClickusing System;using System.Windows.Forms;namespace WindowsFormsApp_Scratch{    public partial class Form1 : Form    {        TreeNode treeViewClickedNode;        ContextMenu mnu = new ContextMenu();        public Form1()                {            InitializeComponent();            // Create the root node.            TreeNode treeNodeRoot = new TreeNode("Documents");            // Add the root node to the TreeView.            treeView1.Nodes.Add(treeNodeRoot);            //Create and add child 2 nodes each with a two item ContextMenuStrip.            string[] childNodeLabels = { "document1.docx", "document2.docx"};            string[] contextItemLabels = { "Action A", "Action B" };            foreach (String childNodeLabel in childNodeLabels)            {                TreeNode treeNode = treeNodeRoot.Nodes.Add(childNodeLabel);                // Create a ContextMenuStrip for this child node.                ContextMenuStrip contextMenuStripChildNode = new ContextMenuStrip                {                    ShowCheckMargin = true,                    ShowImageMargin = false                };
查看完整描述

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

        }

    }


}


查看完整回答
反對(duì) 回復(fù) 2021-06-05
  • 1 回答
  • 0 關(guān)注
  • 176 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)