progress bar in foreach function not working
the program i am designing makes an image by getting the file name of the
image searching for that name in a cdb then making a picture with the data
from that database item that all works what i want to do now is add a
progress bar because if you're doing for a large amount of pics it can
take a while so a progress bar would help keep track here is the code im
using atm but the bar does not advance until the end i want to avoid using
background worker if i can
private void button5_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
string folder = folderBrowserDialog1.SelectedPath;
DirectoryInfo dinfo = new
DirectoryInfo(folderBrowserDialog1.SelectedPath);
FileInfo[] Files = dinfo.GetFiles("*.jpg");
int count = Files.Length;
int current = 0;
foreach (FileInfo file in Files)
{
string path = Path.GetFileNameWithoutExtension(file.Name);
int cardid = Convert.ToInt32(path);
if (Program.CardData.ContainsKey(cardid))
{
DevPro_CardManager.cardmaker.IMG =
LoadBitmap(folderBrowserDialog1.SelectedPath + "//" +
file.Name);
string lev = Program.CardData[cardid].Level.ToString();
comboBox2.SelectedItem = lev;
string att =
Program.CardData[cardid].Attribute.ToString();
if (att == "1")
{
att = "earth";
}
else if (att == "2")
{
att = "water";
}
else if (att == "4")
{
att = "fire";
}
else if (att == "8")
{
att = "wind";
}
else if (att == "16")
{
att = "light";
}
else if (att == "32")
{
att = "dark";
}
else if (att == "64")
{
att = "divine";
}
comboBox1.SelectedItem = att;
if (Program.CardData[cardid].Atk.ToString() == "-2")
{
textBox2.Text = "????";
}
else
{
textBox2.Text =
Program.CardData[cardid].Atk.ToString();
}
if (Program.CardData[cardid].Def.ToString() == "-2")
{
textBox1.Text = "????";
}
else
{
textBox1.Text =
Program.CardData[cardid].Def.ToString();
}
string ctp = Program.CardData[cardid].Type.ToString();
if (ctp == "2" || ctp == "130" || ctp == "65538" ||
ctp == "131074" || ctp == "262146" || ctp == "524290")
{
ctp = "spell";
}
else if (ctp == "4" || ctp == "1048580" || ctp ==
"131076")
{
ctp = "trap";
}
else if (ctp == "129" || ctp == "161")
{
ctp = "ritual";
}
else if (ctp == "65" || ctp == "97")
{
ctp = "fusion";
}
else if (ctp == "8193" || ctp == "8225" || ctp ==
"12321")
{
ctp = "synchro";
}
else if (ctp == "8388609" || ctp == "8388641")
{
ctp = "xyz";
}
else if (ctp == "33" || ctp == "545" || ctp == "1057"
|| ctp == "2081" || ctp == "4129" || ctp == "4194337")
{
ctp = "effect";
}
else if (ctp == "17" || ctp == "4113")
{
ctp = "normal";
}
else if (ctp == "16401")
{
ctp = "token";
}
comboBox3.SelectedItem = ctp;
GenerateCard();
ImageResizer.CropImage(361, 523, pictureBox1.Image,
@"anime cards\" + Path.GetFileName(file.Name));
int cardcount = +1;
label8.Text = cardcount.ToString();
}
current++;
progressBar1.Value = current / count;
}
}
}
No comments:
Post a Comment