I have a program in c# that basically draws points on the screen. A button causes these points to be drawn. Sometimes and it seems completely random, the points are drawn and then vanish for no reason. Why is this happening and how do I fix it?
3 replies to this topic
#1
Posted 29 July 2010 - 09:58 AM
|
|
|
#2
Posted 29 July 2010 - 12:26 PM
Can you post your code?
Check out our update Guidelines/FAQ. When posting code, remember to use code tags -
.
.
#3
Posted 30 July 2010 - 03:27 AM
You must draw points on Paint event, not just when you wish it. If you do not do that, it may happen that something else triggers the Paint event which in turn paints window background using solid brush - hence your points disappear.
Correct way to draw points on button click is to invoke Invalidate method, specifying the region which should contain points. Once done, OnPaint method will be invoked from inside and there is the place to put drawing code.
Correct way to draw points on button click is to invoke Invalidate method, specifying the region which should contain points. Once done, OnPaint method will be invoked from inside and there is the place to put drawing code.
#4
Posted 02 August 2010 - 06:04 AM
That sounds helpful ^ But I'm not sure how to do it. Here' my code
private void plotcolor()
{
Graphics g = this.CreateGraphics();
// g.Clear(Color.LightGray);
int points = 0;
for (points = 0; points <= myarrays.Kmeangroup1x.Count() - 1; points++)
{
Size s = new Size(10, 10);
Point p = new Point((((Convert.ToInt32(myarrays.Kmeangroup1y[points]) * chartvalues.maxwidth) / chartvalues.ymaxvalue) + 50), ((chartvalues.maxheight - (Convert.ToInt32(myarrays.Kmeangroup1x[points]) * chartvalues.maxheight) / chartvalues.xmaxvalue) + 50));
Rectangle r2 = new Rectangle(p, s);
Region r = new Region(r2);
g.FillRegion(Brushes.Red, r);
g.DrawRectangle(Pens.Black, r2);
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









