2017-07-19 45 views
-1

我在列表視圖中添加了一個上下文菜單條'View',其中包含大圖標/小圖標/ Tiles等菜單項。如果選擇了任何項目,C#contextmenustrip不會顯示任何提示

現在每當我選擇任何選項時,相應的視圖會發生變化,但菜單不會像在Windows文件資源管理器中那樣獲得任何標記/指示,它會在所選菜單項中顯示項目符號/點。

有人可以顯示,我怎麼能得到我的上下文菜單的相似點/項目符號?

我已經嘗試CheckOnClick屬性,它讓我打勾標記,但有沒有其他方式,我可以得到那個點?

在此先感謝!

回答

0

我找不到像Windows File Explored的View選項那樣獲得項目符號/點的方法,但是我使用了下面的邏輯並使用選中的狀態來指示所做的選擇。

private void toolStripViewOptions_Click(object sender, EventArgs e) 
{ 
      ToolStripMenuItem selectedOption = sender as ToolStripMenuItem; 

      SetIndicationForSelectedOption(selectedOption); 
} 



private void SetIndicationForSelectedOption(ToolStripMenuItem selectedMenuItem) 
{ 
      ToolStripItemCollection menuItems = (contextMenuStrip.Items[(Int32)toolStripView.Tag] as ToolStripMenuItem).DropDownItems; 

      // Set checked state for only the selected view option and disable same for others. 
      foreach (ToolStripMenuItem item in menuItems) 
      { 
       if (selectedMenuItem == item) 
        selectedMenuItem.Checked = true; 
       else 
        item.Checked = false; 
      } 
} 

這適用於我的要求。

相關問題