The problem is that you are looping in your UI thread.
When you start an app, it has one thread - the UI thread - which handles all the display updates via Events. If your event handler - in this case
button1_Click
loops through the file adding lines to listboxes, copying files etc., and taking enough time that a progress bar is needed, then the single thread is busy for a significant time. Since it can only do one thing at a time, it cannot respond to Events which update screen controls until your handler has exited. So even a progress bar isn't a whole lot of use here as the thread which updates it on the users screen is busy copying files!
The solution is to move long running code into a second thread, freeing up the UI thread for display updates.
That can get complicated, because only the UI thread is allowed to access any Controls (including ListBox and ProgressBar controls) so you have to Invoke such code back onto the UI thread.
There is a solution that is pretty easy to use though: the
BackgroundWorker Class (System.ComponentModel) | Microsoft Docs[
^] allows you to report progress back to the UI thread which can update ListBoxes, progress bars, etc.
private void FrmMain_Shown(object sender, EventArgs e)
{
BackgroundWorker work = new BackgroundWorker();
work.WorkerReportsProgress = true;
work.DoWork += Work_DoWork;
work.ProgressChanged += Work_ProgressChanged;
work.RunWorkerCompleted += Work_RunWorkerCompleted;
work.RunWorkerAsync();
}
private void Work_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
private void Work_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void Work_DoWork(object sender, DoWorkEventArgs e)
{
}