Note that there are some explanatory texts on larger screens.

plurals
  1. POPaintEventHandler logical issue
    primarykey
    data
    text
    <p>I am creating a few pictureboxes dynamically, then assigning the following:</p> <pre><code>// class variable public String PaintLabel; // private void Form2_Load(object sender, EventArgs e) //begin loop this.PaintLabel = serialno; Shapes[i].Paint += new PaintEventHandler(ctl_Paint); // end loop // my event override private void ctl_Paint(object sender, PaintEventArgs e) { Control tmp = (Control)sender; using (Font myFont = new Font("Arial", 9, FontStyle.Bold)) { e.Graphics.DrawString(this.PaintLabel, myFont, Brushes.LightYellow, new Point(62, 2)); } // using (Font myFont = new Font("Arial", 10)) } // private void ctl_Paint(object sender, EventArgs e) </code></pre> <p>It is supposed to create the picture boxes and write a different serial number on each one. But it ends up writing the last serial number found on all of the picture boxes</p> <p>EDIT:</p> <p>Ok, your solution is very advanced for me. But I have tried to understand it.</p> <p>I have added your piece of code into mine.</p> <p>Then changed my picture box array as follows</p> <pre><code>MyControl[] Shapes = new MyControl[Num_Picbox]; </code></pre> <p>In my loop I then did the following</p> <pre><code>Shapes[i].SerialNumber = serialno; Shapes[i].Paint += new PaintEventHandler(ctl_Paint); </code></pre> <p>But when I compile and run the code it doesnt draw any serial number on the picturebox.</p> <p>RESOLUTION:</p> <p>Thank your for all your help. I changed your </p> <pre><code>var PaintLabels = new Dictionary&lt;Control, string&gt;(); </code></pre> <p>to</p> <pre><code>Dictionary&lt;Control, string&gt; PaintLabels = new Dictionary&lt;Control, string&gt;(); </code></pre> <p>Which sorted it out, the paint event couldnt see the local variable. </p>
    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. 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