C# - Add, update, delete flow layout panel controls at runtime @JFLHV
C# - Add, update, delete flow layout panel controls at runtime  @JFLHV
Uploaded July 2023 | Updated November 2026, 1 day ago
#csharp example to add, update and delete controls at runtime inside a flowlayoutpanel. A picturebox and labels are created to show a movie image, title and release date.

.cs files in video:
drive.google.com/drive/folders/1XI4zIjOwWX9ET2s-jjY__VXiBSqzn3Ff?usp=share_link

private void AddMovieToUI(Movie movie)
{
//Create panel
Panel panel;
panel = new Panel();
panel.Name = String.Format("PnlMovie{0}", movie.Id);
panel.BackColor = Color.White;
panel.Size = new Size(125, 205);
panel.Margin = new Padding(10);
panel.Tag = movie.Id;

//Create picture box
PictureBox picBox;
picBox = new PictureBox();
picBox.Name = String.Format("PbMovieImage{0}", movie.Id);
picBox.Size = new Size(100, 148);
picBox.Location = new Point(12, 10);
picBox.SizeMode = PictureBoxSizeMode.Zoom;

if (File.Exists(movie.ImagePath))
picBox.Image = Image.FromFile(movie.ImagePath);

picBox.Tag = movie.Id;

//Create title label
Label labelTitle;
labelTitle = new Label();
labelTitle.Name = String.Format("LblMovieTitle{0}", movie.Id);
labelTitle.Text = movie.Title;
labelTitle.Location = new Point(12, 165);
labelTitle.ForeColor = Color.Black;
labelTitle.Font = new Font(this.Font.FontFamily, 9.5f, FontStyle.Regular);
labelTitle.AutoSize = true;
labelTitle.Tag = movie.Id;

//Create year label
Label labelYear;
labelYear = new Label();
labelYear.Name = String.Format("LblMovieYear{0}", movie.Id);
labelYear.Text = movie.ReleaseDate.Year.ToString();
labelYear.Location = new Point(12, 185);
labelYear.ForeColor = Color.Gray;
labelYear.Font = new Font(this.Font.FontFamily, 9.5f, FontStyle.Regular);
labelYear.Tag = movie.Id;

//Set Context Menu
panel.ContextMenuStrip = contextMenuStrip1;

//Add controls to panel
panel.Controls.Add(picBox);
panel.Controls.Add(labelTitle);
panel.Controls.Add(labelYear);

//Add Event Handlers
panel.DoubleClick += new EventHandler(Edit_DoubleClick);

foreach (Control c in panel.Controls)
{
c.DoubleClick += new EventHandler(Edit_DoubleClick);
}

//Add panel to flowlayoutpanel
flowLayoutPanel1.Controls.Add(panel);
}




private void UpdateMovieInUI(Movie movie)
{
Control control;
PictureBox picBox;
string name;

//Find picturebox and update movie image
name = String.Format("PbMovieImage{0}", movie.Id);
control = this.Controls.Find(name, true).FirstOrDefault();
picBox = (PictureBox)control;

if (File.Exists(movie.ImagePath))
picBox.Image = Image.FromFile(movie.ImagePath);
else
picBox.Image = null;

//Find movie title label and update text

name = String.Format("LblMovieTitle{0}", movie.Id);
control = this.Controls.Find(name, true).FirstOrDefault();
control.Text = movie.Title;

//Find movie year label and update text
name = String.Format("LblMovieYear{0}", movie.Id);
control = this.Controls.Find(name, true).FirstOrDefault();
control.Text = movie.ReleaseDate.Year.ToString();
}


private void DeleteMovieFromUI(Movie movie)
{
Control panel;
string name;

//Find panel
name = String.Format("PnlMovie{0}", movie.Id);
panel = this.Controls.Find(name, true).FirstOrDefault();

//Remove event handlers
panel.DoubleClick -= new EventHandler(Edit_DoubleClick);

foreach (Control c in panel.Controls)
{
c.DoubleClick -= new EventHandler(Edit_DoubleClick);
}

//Remove panel
flowLayoutPanel1.Controls.Remove(panel);
panel.Dispose();
}
C# - Add, update, delete flow layout panel controls at runtimeRun .NET MAUI Windows app from command lineSearch for multiple file types Windows ExplorerOpen hard drive to remove data diskZoom Effect in VSDC Free Video EditorChange duration of freeze frame in iMovie macOSiMovie - Creating a custom timerExport iMovie vertical videos in HD on Mac5 star rating green screeniMovie zoom in and out smoothly on MacC# - Simulate keystrokes with SendInput (codeproject implementation)Fading circle green screen overlay
JFLHV |

C# - Add, update, delete flow layout panel controls at runtime

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER