public partial class Frm_MenuFlutuante : Form
{
public Frm_MenuFlutuante()
{
InitializeComponent();
}
ToolStripMenuItem DesenhaItemMenu(string text)
{
var vToolTip = new ToolStripMenuItem();
vToolTip.Text = text;
return vToolTip;
}
ToolStripMenuItem DesenhaSubItemMenu(ToolStripMenuItem menuPrincipal, string _subMenu)
{
menuPrincipal.DropDownItems.Add(_subMenu);
return menuPrincipal;
}
private void Frm_MenuFlutuante_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
var _posicaoX = e.X;
var _posicaoY = e.Y;
//MessageBox.Show("Botão direito na Posição:" + " X: " + _posicaoX.ToString() + " Y: " + _posicaoY.ToString()); ;
var ContextMenu = new ContextMenuStrip();
ToolStripMenuItem Menu_01 = DesenhaItemMenu("Item do Menu 01");
ToolStripMenuItem Menu_02 = DesenhaItemMenu("Item do Menu 02");
ToolStripMenuItem Menu_03 = DesenhaItemMenu("Item do Menu 03");
ContextMenu.Items.Add(Menu_01);
ContextMenu.Items.Add(DesenhaSubItemMenu(Menu_01, "Item do SubMenu 01"));
ContextMenu.Items.Add(DesenhaSubItemMenu(Menu_01, "Item do SubMenu 02"));
ContextMenu.Items.Add(Menu_02);
ContextMenu.Items.Add(Menu_03);
ContextMenu.Show(this, new Point(_posicaoX, _posicaoY));
}
}
}