c# - PaintEventHandler logical issue -


I am dynamically creating some image boxes, then I am specifying the following:

 < Code> // class variable public string color label; // Start Private Zero Form 2_load (Object Sender, Event Argus E) // Loop. Paint Label = Serialano; Size [I] Paint + = new paint event handler (ctl_Paint); // End Loop // My Event Private Zero ctl_Paint Override (Object Sender, PaintEventArgs E) {Control TMP = (Control) Sender; (Font myFont = new font ("Arial", 9, font style.)) (E. Graphics.Drustring (This colorbell, my font, brush, light goodbye, new point (62, 2)); // (Font myFont = new font ("Aerial", 10))} // Private Zero ctl_Paint (Object Sender, EventArgues E)  

This image is about to create a box and each Type a different serial number on one, but it ends up typing the last serial number found in all the picture boxes

Edit:

OK, your solution is very advanced to me but I have tried to understand it.

The piece has been added to me.

Then my picture box array has been changed as follows

 > MyControl [] size = New MyControl [Num_Picbox];  

I did the following in my loop

  shapes [i] .SerialNumber = serialno; size [I]. Paint + = new paint event handler (ctl_Paint);  

But when I Compile the code and I run, so it brings no serial number on the picture box.

Resolution:

Thanks HELP I changed your

  var paint lobals = new dictionary & lt; Control, string & gt; ();  

to

  glossary & lt; Control, string & gt; Pentathables = New Dictionary & lt; Control, string & gt; ();  

How it was resolved, the paint event can not see the local variable

This is because you are updating the value of the string field within the loop, updating its value until it is looped, when the last value is in the field:

  // startup loop // Here is your problem; There is only one paint label ***. Colorbell = serial; Size [I] Paint + = new paint event handler (ctl_Paint); // end loop  

is to create PaintLabel in an array in an array, as the shapes are or easier than that, a Dictionary , which also refers to between shapes and serial numbers:

  var paint labels = new dictionary & lt; Control, string & gt; (); // Starting Loop Pantalables Add (size [i], serialino); Size [I] Paint + = new paint event handler (ctl_Paint); // End Loop // // Paint Event E. Graphics. Drawstring (Pentlabel (TMP), My fonts, Brush, light, new point (62, 2));  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -