Hi
I am create one application in which add some selected images into flowlayout panel.how to select particular image from flowlayout panel and remove this selected images from flowlayout panel
Regards,
Shailaja

Recommended Answers

All 3 Replies

Here is some code to show you what you asked:

// 2nd param false if not searching child controls of control...
            Control[] ctrls = flowLayoutPanel1.Controls.Find("searchkey", false);

            // Note: only one can be selected (made active), so if Find returns more than one,
            // the last one in array will be the selected control using this loop...
            foreach (Control c in ctrls)
                c.Select();

            // if only one control returned (exact match), make it active...
            if (ctrls.Length > 0)
            {
                ctrls[0].Select();

                // to remove this control...
                flowLayoutPanel1.Controls.Remove(ctrls[0]);
            }

Every FlowLayoutPanel has a Controls collection, us it like this:

if(panel1.Controls.Contains(MyPict))
   {
      panel1.Controls.Remove(MyPict);
   }

You can select an image by clicking on it if you capture its Click() event. The following example shows how to add an event handler to the control at creation.

When a picturebox is clicked on a border is added to highlight it and it is stored in a variable to track which control is selected:

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private PictureBox _selectedPicture;

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                PictureBox pb = new PictureBox();
                pb.Image = Properties.Resources.pic1;
                pb.Name = "pic" + i.ToString();
                pb.Click += new EventHandler(picture_click);
                flowLayoutPanel1.Controls.Add(pb);
                
            }
        }

        void picture_click(object sender, EventArgs e)
        {
            if (_selectedPicture != null)
                _selectedPicture.BorderStyle = BorderStyle.None;
            _selectedPicture = (PictureBox)sender;
            _selectedPicture.BorderStyle = BorderStyle.FixedSingle;
        }
    }
}
commented: Thank You +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.