Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could keep track of the images in another array.</p> <p>After you add the image to the view you should also add it to the array:</p> <pre><code>images[j] = mole; </code></pre> <p>Then later:</p> <pre><code>if (CounterArray[j] == 0) { grid_Main.Children.Remove(images[j]); } </code></pre> <p>But using static arrays and separating data is not a good idea.</p> <p>If you can you should better aggregate all the metadata and the image together in the same structure:</p> <pre><code>class Mole { public int Counter { get; set; } public Control Image { get; set; } } </code></pre> <p>and manage them in a single <em>List&lt;Mole></em>; adding and removing them will be simpler.</p> <p>Here is some code that illustrates the idea (won't compile):</p> <pre><code>class Mole { public int X { get; set; } public int Y { get; set; } public int Counter { get; set; } public Control Image { get; set; } public bool IsNew { get; set; } } class Test { IList&lt;Mole&gt; moles = new List&lt;Mole&gt;(); private static void AddSomeMoles() { moles.Add(new Mole{ X = rand.Next(100), Y = rand.Next(100), Counter = 3, Image = new PictureBox(), IsNew = true }); } private static void DisplayMoles() { foreach (Mole mole in moles) { if (mole.IsNew) { grid_Main.Children.Add(mole.Image); mole.IsNew = false; } } } private static void CleanupMoles() { foreach (Mole mole in moles) { mole.Counter -= 1; if (mole.Counter &lt;= 0) { grid_Main.Children.Remove(mole.Image); moles.Remove(mole); } } } static void Main() { while (true) { AddSomeMoles(); DisplayMoles(); Thread.Sleep(1000); CleanupMoles(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload