public void timer1_Tick(object sender, EventArgs e) { if (progress.Value > 0) { progress.Value -= 1; lbltimeleft.Text = Convert.ToString(progress.Value) + "s"; } else { // YGE : Just to call it once if (!bTimeIsUpDelegateCalled) { bTimeIsUpDelegateCalled = true; // YGE : so, i create an argument and fill it SpellBarEventArgs Args = new SpellBarEventArgs(spellName, spellDuration); TimeIsUpEvent(this, Args); } internalCounter++; if (internalCounter % 2 == 0) { groupBox1.BackColor = System.Drawing.Color.White; //lblspellname.ForeColor = System.Drawing.Color.Red; } else { groupBox1.BackColor = System.Drawing.Color.Gray; //lblspellname.ForeColor = System.Drawing.Color.Blue; } } }
public void SpellBarTimeIsUp(object sender, SpellBarEventArgs e) { // YGE : Ok, called when a bar reaches 0 !! Debug.WriteLine(e.spellName + " bar reached 0"); // YGE : now, i parse my ArrayList to find and remove that spellbar // can do it with a while, for or an iterator int NumToKill = -1; for (int i = 0; i < SpellBarCollection.Count; ++i) { spellbar SpellBarRef = (spellbar)SpellBarCollection[i]; // cast my ArrayListMember to a SpellBar if (SpellBarRef.spellName == e.spellName) // YGE : i got the spell name that reaches 0 from the event, could probably pass a SpellBar Reference too, or cast the "sender" object { NumToKill = i; } } // YGE : found it, i stop displaying it, and kill it if (NumToKill > 0) { spellbar SpellBarToKill = (spellbar)SpellBarCollection[NumToKill]; panel1.Controls.Remove(SpellBarToKill); // YGE : Remove it from the panel SpellBarCollection.RemoveAt(NumToKill); // YGE : Remove it from my list // the garbage collector will remove the unused spellbar from memory automatically, as long as it s not referenced anywhere anymore // YGE : now, i fill the blanks in the display for (int i = 0; i < SpellBarCollection.Count; ++i) { spellbar SpellBarRef = (spellbar)SpellBarCollection[i]; SpellBarRef.Location = new Point(10, 10 + i * 36); } } }