Doubt about searching buttons [duplicate]

0

The idea is:

  • In the "Find Game ..." field, I look for the buttons, which are already named with their respective games: btnArcheAge , btnDiablo3 , btnWoW , etc. The tags are also already named with the actual name of each game.

  • Obs : The buttons were placed in a FlowLayoutPanel

    I need a little push with the code, I do not know where to start. This is the picture I have of the old post they made for me.

    Programandcode

    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();
            }
    
        }
    
        public static bool ContainsIgnoreCase(this string source, string search)
        {
            return source.IndexOf(search, StringComparison.CurrentCultureIgnoreCase) >= 0;
        }
    
    
        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)
        {
    
        }
    
    
    }
    

    }

        
    asked by anonymous 08.05.2017 / 11:23

    1 answer

    0

    Well, I've done all the code for you in the other post , you just missed a part of it.

    As I said in one of the items

      

    Define when the search will take place. In the example, I defined that the search would occur whenever the user types something in the Search TextBox, using the TextChanged event.

    You already have the code that does the search (in the other post), now you only have to place it inside the TextChanged event of TextBox . For the names in your code, it should be txtBuscarJogo_TextChanged .

        
    08.05.2017 / 13:42