How to add boot to a panel?

Asked

Viewed 292 times

0

inserir a descrição da imagem aqui

I need to add a button to my flowLayoutPanel when clicked on the add button ( btnAdd ). My Panel is called mainPanel

NOTE : I managed to add, but I need to add the size of the other buttons.

CODE

namespace SlidingPanel
{

public partial class Form1 : Form
{

    private readonly Button[] _todosBotoes;
    public Form1()
    {

        InitializeComponent();
        //Passo 1

        _todosBotoes = mainPanel.Controls.OfType<Button>().ToArray();
    }

    private void pictureBox3_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void bunifuImageButton1_Click(object sender, EventArgs e)
    {

        if(panel1.Width == 350)
        {    

            panel1.Visible = true;
            panel1.Width = 65;

        }

    }

    private void btnVoltar_Click(object sender, EventArgs e)
    {
        if(panel1.Width == 65)
        {

            panel1.Visible = true;
            panel1.Width = 350;


        }

    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {

        if (panel1.Width == 350)
        {
            btnVoltar.Hide();

        }
        else
        {

            btnVoltar.Show();
        }

    }



    private void txtBuscarJogo_TextChanged(object sender, EventArgs e)
    {
        //Passo 2.1
        var controles = _todosBotoes.Where(btnArcheAge => (btnArcheAge.Tag as String ?? btnArcheAge.Text).ContainsIgnoreCase(txtBuscarJogo.Text)).ToArray();
        //Passo 2.2
        mainPanel.Controls.Clear();
        //Passo 2.3
        mainPanel.Controls.AddRange(controles);
    }

    private void lblAmigos_Click(object sender, EventArgs e)
    {

    }

     private void btnAdicionar_Click(object sender, EventArgs e)
     {
         for (int i = 0; i < 1; i++)
        {
            Button button = new Button();
            button.Tag = i;


            mainPanel.Controls.Add(button);
        }
     }

}
}

namespace MyMethod
{
    public static class MyExtensions
    {
        public static bool ContainsIgnoreCase(this string source, string search)
        {
            return source.IndexOf(search, StringComparison.CurrentCultureIgnoreCase) >= 0;
        }
    }
}
  • The Buttons array, which is the source of the Buttons, is readyonly, but just vc add one more element to it, and fill the panel again

  • OK I managed to adjust the size, but it has how to inherit the features, color, size of another button created?

  • You don’t need this 0 to 1, rsrs, to copy the properties: Button.Size = _All Photos[0]. Size;

  • It didn’t even work. It’s to erase all the code inside the btn and just put this?

  • Oh I got it, I got it, but the color ? how do I get it from that button? for example the color is Aliceblue of the buttons

  • button.Backcolor = Color.Aliceblue; I did it, it even worked mass, does it have another shape? kk

  • then, a question: Since you have this option to add, you would not have to store somewhere to when close the application and when opening again not have lost this information ?

  • would be nice, but for now I’m just learning some functions kk

  • @Dáriosabaini Your intention is just to create a new button with the same visual pattern as the others?

  • To put the button color the same color as another, just do it as follows: button.BackColor = buttonbase.BackColor; in case you change the buttonbase, by the name of the button from which you want to pick the color.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.