2016-03-08 74 views
1

我使用c#/ winforms和devex xtratabcontrol。我需要能夠右鍵單擊標題標題並獲取上下文菜單才能顯示。我試着根據這個鏈接的第一個答案努力工作:TabControl Context Menu,但由於某種原因,當我點擊時,我看到事件發生,但沒有出現在屏幕上。ContextMenuStrip沒有顯示在devex上XtraTabControl

這是我想要的代碼:

ContextMenuStrip menuStrip=new ContextMenuStrip(); 
ContextMenu menu=new ContextMenu(); 
menu.MenuItems.Add("click me", new EventHandler(temp_click)); 
menuStrip.ContextMenu = menu; 
mainTabControl.MouseClick += MainTabControl_MouseClick; 


private void temp_click(object sender, EventArgs e) 
{ 
    //nothing for now 
} 

private void MainTabControl_MouseClick(object sender, MouseEventArgs e) 
{ 
    if (e.Button == MouseButtons.Right) 
    { 
     this.menuStrip.Show(this.mainTabControl, e.Location); 
    } 
} 

你的幫助是非常感謝!

回答

1

嘗試增加ToolStripMenuItems到您的ContextMenuStrip:

ContextMenuStrip menuStrip = new ContextMenuStrip(); 
ToolStripMenuItem tsmi = new ToolStripMenuItem(); 
tsmi.Text = "click me"; 
tsmi.Click += temp_click; 
menuStrip.Items.Add(tsmi); 
+0

作品!謝謝!! –