I want my progress bar to start running when the user presses the Validate button. However I can only get the progress bar to move when I click on it instead. How do I link my progress bar to start when the I press the Validate button.
private void ValidateButton_Click(object sender, EventArgs e)
{
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(FileNameBox.Text);
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
counter++;
}
file.Close();
System.Console.WriteLine("There were {0} records.", counter);
// Suspend the screen.
System.Console.ReadLine();
}
private void ProgressBar_Click()
{
// Display the ProgressBar control.
ProgressBar.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
ProgressBar.Minimum = 1;
// Set Maximum to the total number of files to copy.
ProgressBar.Maximum = FileNameBox.TextLength;
// Set the initial value of the ProgressBar.
ProgressBar.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
ProgressBar.Step = 1;
// Loop through all files to copy.
for (int x = 1; x <= FileNameBox.TextLength; x++) ;
}
}
The FileNameBox is a file path the user has chosen. This works as intended.