Im using Visual Studio 2010 Ultimate and Im trying to convert some images using a progress bar and two labels but the text of both labels is not shown and the program just shows the labels with white background.

p.s. The labels backcolor is “Control” (not transparent)
I have two forms 1st the “Main” form and the “ProgressDialog” form
in the main form when I click my “Save” button
//copy the filenames to a new array to sort them
string[] FileNames = openDialog.FileNames;
Array.Sort(FileNames);
//create an instance of my progress dialog
ProgressDialog progress = new ProgressDialog(this, 100/FileNames.Length);
progress.ShowProgress();
//save all the files in the array
for (int i = 0; i < FileNames.Length; i++)
{
//call the SaveImage method
SaveImage(FileNames[i], 597, 412, Fill);
//increase the progresbar and set the label text of the progress dialog to the filename
progress.Increase(FileNames[i]);
}
progress.Close();//close progress dialog and re-enable the main form
…and here the code of my “ProgressDialog” form:
Bar: name of the progress bar
Comment: name of the label with the image path as text
private Form SenderForm;// the "Main" form
private int Step; //value to increase in the progress bar
public ProgressDialog(Form sender, int step)//constructor
{
InitializeComponent();
SenderForm = sender;
Step = step;
}
//disable cose button
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
//re-enable the "Main" form
private void ProgressDialog_FormClosed(object sender, FormClosedEventArgs e)
{
SenderForm.Enabled = true;
SenderForm.Activate();//activate form
}
//increase the value of the progressbar
public void Increase( string comment=null, int step=0)
{
//if step is 0 -> use the Step of the constructor
if (step==0) step = Step;
//if the comment (the current file name) is != of null
if (comment!=null)
Comment.Text = comment;//use the comment of the parameter
//increase progressbar
Bar.Value += step;
}
//show "ProgrssDialog" form
public void ShowProgress()
{
this.Show();
SenderForm.Enabled = false;//disable the main form
}
It happens because mainthread is too busy to update label in ui
U should do the process in a thread to prevent the UI hangs
Have look to this postC# question on preventing GUI from becoming sluggish when using backgroundworker/thread