ユーザーがボタンであるコントロールを「右クリック」したときに表示されるコンテキストメニューを作成したいと思います。残念ながら、一部のボタンは無効になっています。誰かが私を助けて、コンテキストメニューも与える方法を教えてもらえますか?
私の(機能していない)試してみてください:
private void ShowRightClickMenu(object sender, MouseEventArgs e)
{
ContextMenu Temp = new ContextMenu();
if (e.Button == MouseButtons.Right && secondTagObj[Convert.ToInt32(((Button)sender).Tag)].typ != string.Empty)
{
this.ContextMenu = Temp; // works
Temp.MenuItems.Add("Create.."); //works
Temp.MenuItems.Add("Delete"); // works
}
if (raster[Convert.ToInt32(((Button)sender).Tag)].Enabled == false && e.Button == MouseButtons.Right)
{
this.ContextMenu = Temp; // works not
Temp.MenuItems.Add("New..."); // works not
}
else
{
this.ContextMenu = Temp; // works, but only if button is visible
Temp.MenuItems.Add("New..."); // works, but only if button is visible
}
}
よろしくお願いします。