-1

Is it possible to have a Search box on a form that searches through the labels in a panel with numerous tabs to then to go that label?

2 Answers2

2

Yes you can, you can search for the text in all the controls and then switch the selected Tab as below

 foreach (TabPage tab in tabControl1.TabPages)
            {
                var controls = tab.Controls; 
                foreach(Control c in controls)
                    if (c.GetType() == typeof(Label))
                    {
//depends if you want to search by label text or name 
                        string txt = c.Text;
                        string name = c.Name;

                        if (txt == textbox1.Text.Trim()) tabControl1.SelectedTab = tab;
                    }
            }
Alaa Mohammed
  • 382
  • 2
  • 14
0
 Is there anyway of talking off case sensitive 
  private void button4_Click(object sender, EventArgs e)
    {
        foreach (TabPage tab in tabControl1.TabPages)
        {
            var controls = tab.Controls;
            foreach (Control c in controls)
                if (c.GetType() == typeof(Label))
                {
                    //depends if you want to search by label text or name 
                    string txt = c.Text;
                    //string name = c.Name;
                    //MessageBox.Show(txt);
                    if (txt.Contains (textBox2.Text.Trim())) tabControl1.SelectedTab = tab;
                    //MessageBox.Show(textBox2.Text.Trim());
                }