0
The thing is, I need to add these tools, exactly as shown in the image.
I just need a little push on how to get started.
Insert text
Insert Image
Delete (button)
CODE
namespace frmLoginRPG
{
public partial class frmMenuPrincipal : Form
{
private readonly Button[] _todosBotoes;
public frmMenuPrincipal()
{
InitializeComponent();
//Passo 1
_todosBotoes = _mainPanel.Controls.OfType<Button>().ToArray();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
//Passo 2.1
var controles = _todosBotoes.Where(btnRifts => (btnRifts.Tag as String ?? btnRifts.Text).ContainsIgnoreCase(txtBuscarJogo.Text)).ToArray();
//Passo 2.2
_mainPanel.Controls.Clear();
//Passo 2.3
_mainPanel.Controls.AddRange(controles);
}
private void button2_Click(object sender, EventArgs e)
{
}
private void btnAdicionar_Click(object sender, EventArgs e)
{
Button button = new Button(); //criando botão
button.Size = _todosBotoes[0].Size; //criando botão, puxando o tamanho dos outros botões
button.BackColor = Color.AliceBlue; //definindo cor do botão
_mainPanel.Controls.Add(button); //Adicionando botão no _mainPanel
button.ContextMenuStrip = this.contextMenuStrip1; //Adicionando contextMenuStrip assim que o Botão for criado.
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;
}
}
}
`
But I need those functions working, delete the button, put picture on the button, change description on the button... got it?
– Dário Sabaini
@Dario, just exchange the Messagebox of the rovann code for the function you need. Insert for example would be: Button btn = (Button) Sender; btn.Text = text;
– Leonardo Moura
Assuming text is a String you set, or asked the user.
– Leonardo Moura
I have no way to put working pq the 'insert text' as q the user will insert ? the delete, will delete from where ? understand.... rs only the concept
– Rovann Linhalis
I understood, but in case I would be no user, only myself! Delete the Panel button insert text description on the button and put image on the button. all through the Contextmenu
– Dário Sabaini
I don’t have a database, nothing... It’s pretty raw
– Dário Sabaini
The delete function could look something like this: Button btn = (Button) Sender; _mainPanel.Controls.Remove(btn);
– Leonardo Moura
The other two, you need to get the text and image from somewhere. An option would be to open a new Form by passing the button as parameter and inside this Form, change the necessary properties as text and image.
– Leonardo Moura
It is missing that you design your application before developing and knowing which resource registration it will need. Since the first question you asked where I answered with example where a Datatable was origin of buttons. Now if you need to store this information, edit, insert or delete, none of this static part of the buttons inserted directly on the screen makes sense, you would have to change this whole part.
– Rovann Linhalis