Hello everyone I'm trying to search for control in flowlayoutpanel by taking input from textBox text and determine if that input is equal to the panel control label text, but when I typed in input on the textBox nothing happened.
This is how the panel look like
The created panel consists of several control: Label, Picturebox, Button, 2 labels. And i want to keep all of the controls as well when the user searched for the panel based on the label text.
This is how the panel (and labels) was created:
int top = 275;
int h_p = 100;
var panelTxt = new Guna2Panel() {
Name = panName + itemCurr,
Width = 240,
Height = 262,
BorderRadius = 8,
FillColor = ColorTranslator.FromHtml("#121212"),
BackColor = Color.Transparent,
Location = new Point(600, top)
};
top += h_p;
flowLayoutPanel1.Controls.Add(panelTxt);
var mainPanelTxt = ((Guna2Panel)flowLayoutPanel1.Controls[panName + itemCurr]);
var textboxPic = new Guna2PictureBox();
mainPanelTxt.Controls.Add(textboxPic);
textboxPic.Name = "TxtBox" + itemCurr;
textboxPic.Width = 240;
textboxPic.Height = 164;
textboxPic.BorderRadius = 8;
textboxPic.SizeMode = PictureBoxSizeMode.CenterImage;
textboxPic.Enabled = true;
textboxPic.Visible = true;
Label titleLab = new Label();
mainPanelTxt.Controls.Add(titleLab);
titleLab.Name = "LabVidUp" + itemCurr;
titleLab.Font = new Font("Segoe UI Semibold", 12, FontStyle.Bold);
titleLab.ForeColor = Color.Gainsboro;
titleLab.Visible = true;
titleLab.Enabled = true;
titleLab.Location = new Point(12, 182);
titleLab.Width = 220;
titleLab.Height = 30;
titleLab.Text = getName;
titlePanelSearch = titleLab;
Guna2Button remButTxt = new Guna2Button();
mainPanelTxt.Controls.Add(remButTxt);
remButTxt.Name = "RemTxtBut" + itemCurr;
remButTxt.Width = 39;
remButTxt.Height = 35;
remButTxt.FillColor = ColorTranslator.FromHtml("#4713BF");
remButTxt.BorderRadius = 6;
remButTxt.BorderThickness = 1;
remButTxt.BorderColor = ColorTranslator.FromHtml("#232323");
remButTxt.Image = FlowSERVER1.Properties.Resources.icons8_garbage_66;
remButTxt.Visible = true;
remButTxt.Location = new Point(189, 218);
remButTxt.BringToFront();
I tried to loop through the controls in flowlayoutpanel and tried to search for titleLab
label inside the created panel which what I'll use to search for the panel.
This is the textBox input:
private void guna2TextBox5_TextChanged(object sender, EventArgs e) {
foreach(Control c in flowLayoutPanel1.Controls) {
if(c.GetType() == typeof(Label)) {
Label defineLabel = (Label)c;
if(!defineLabel.Text.ToLower().Contains(guna2TextBox5.Text.ToLower())) {
flowLayoutPanel1.Controls.Remove(c);
}
}
}
}
I type in 'Untitled' on the textBox for testing but nothings happened the panel just stays how it was before I typed anything in while I was expecting for panel with label text 'Untitled' to show up and remove the other panels with label that does not equal to the textBox input.
Refer links: