c# - Making a void dynamic -


I make some image boxes dynamic, but I do not know how to take personal action on clicks.

  PictureBox [] app = new picturebox [file. Length]; Int i = 0, prev = 20; Foreign currency (string element in file) {app [i] = new image box (); App [ii] Background Image = Image. RemoveFile (Element. Remove (Element. Long-3) + "PNG"); App [ii] Place = new point (previous, 85); App [ii] Size = new size (100, 100); App [ii] .name = "test" + i; App [i] Click + = New EventHandler (Play (element, DIR)); This.Controls.Add (application [i]); I ++; Prev = 20; } Private Zero Run (String Element, String DIR) {MessageBox.Show (element); }  

Please help me how I can do this! Thanks!

Try to avoid using the delegates / tasks within a foreach loop, and if you do If there is a copy of the object, no variable in the loop statement.

  var elementCopy = element; ... app [i] Click + = (Sender, EVT) => Run (elementCopy, dir);  

If you use the element directly, then it is a chance that it will always use the minimum element for the representative

Edit: View it: < / P>

It explains why you should do whatever I have said in depth.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -