mardi 3 mars 2015

Setting brush to point in panel

I am using Windows Forms at new Visual Studio 15 CPT6. I have a class where i set brush to my object example of class:


class Group { private SolidBrush brush; private List points = new List(); private Color color;



public Group()
{
Random randomGen = new Random();
color = Color.FromArgb(randomGen.Next(0, 220), randomGen.Next(0, 220), randomGen.Next(0, 220));
brush = new SolidBrush(color);

Thread.Sleep(10); //This is MUST!
}


Then in main program i create for example 50 objects of this class and it sets all of them to same color if i dont put Thread.Sleep(10); it works ok if go with step by step debuging but if i just run it it doesnt.


Here is example of calling this methods from main class:



Graphics graphics = mainPanel.CreateGraphics();

for (int i = 0; i < points.Count; i++)
{
Group newGroup = new Group();
newGroup.addPointToGroup(points[i]);

groups.Add(newGroup);

graphics.FillEllipse(newGroup.getGroupBrush(), points[i].getX(), points[i].getY(), 8, 8);
}

Aucun commentaire:

Enregistrer un commentaire