Doubt over contextMenuStrip

0

It'sthefollowing,Ineedtoaddthesetoolsexactlyasshownintheimage.

Ijustneedapush,howtogetstarted.

  

Inserttext

    

InsertImage

    

Delete(button)

CODE

namespacefrmLoginRPG{publicpartialclassfrmMenuPrincipal:Form{privatereadonlyButton[]_todosBotoes;publicfrmMenuPrincipal(){InitializeComponent();//Passo1_todosBotoes=_mainPanel.Controls.OfType<Button>().ToArray();}privatevoidrichTextBox1_TextChanged(objectsender,EventArgse){//Passo2.1varcontroles=_todosBotoes.Where(btnRifts=>(btnRifts.TagasString??btnRifts.Text).ContainsIgnoreCase(txtBuscarJogo.Text)).ToArray();//Passo2.2_mainPanel.Controls.Clear();//Passo2.3_mainPanel.Controls.AddRange(controles);}privatevoidbutton2_Click(objectsender,EventArgse){}privatevoidbtnAdicionar_Click(objectsender,EventArgse){Buttonbutton=newButton();//criandobotãobutton.Size=_todosBotoes[0].Size;//criandobotão,puxandootamanhodosoutrosbotõesbutton.BackColor=Color.AliceBlue;//definindocordobotão_mainPanel.Controls.Add(button);//Adicionandobotãono_mainPanelbutton.ContextMenuStrip=this.contextMenuStrip1;//AdicionandocontextMenuStripassimqueoBotãoforcriado.MessageBox.Show("                  CRIADO        ");

        }
    }



}
namespace MyMethod
{
    public static class MyExtensions
    {
        public static bool ContainsIgnoreCase(this string source, string search)
        {
            return source.IndexOf(search, StringComparison.CurrentCultureIgnoreCase) >= 0;
        }
    }
}
'
    
asked by anonymous 20.05.2017 / 02:30

1 answer

0

You create a contextMenu and set it in the Button property, in the click event you will know which button came the click through sender :

    private void inserirTextoToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string name = ((Button)sender).Name;
        MessageBox.Show("Você clicou para inserir no botão: " + name);
    }

    private void excluirToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string name = ((Button)sender).Name;
        MessageBox.Show("Você clicou para excluir o botão: " + name);
    }
    
20.05.2017 / 04:16