Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code

this is in the picturebox1_move
panel1.Refresh();


and in the picurebox1_paint i got

//here
           Graphics c = panel1.CreateGraphics();
           Pen red = new Pen(Color.Red, 5);
           g.DrawLine(red, new Point(picturebox1.Location.X, picturebox1.Location.Y), new Point(picturebox1.Location.X, panel1.Height));


my problem is when the panel the graphic is in it keeps flashing when it is refreshed and it looks very un-professional, I was wondering if I can get this refresh thing with-out these annoying flashing
Posted

You could try setting the Form.DoubleBuffered property to true.
Otherwise, why are you refreshing a panel when you move a picturebox, and why the heck are you painting in the panel when you paint the picturebox? (Assuming you meant Graphics g = panel... in your code above not Graphics c = panel...)
 
Share this answer
 
If you're overriding paint you shouldn't be creating your own graphics object.

Are you trying to draw the panel or the picture box? You shouldn't confuse the refresh of one control with the other. Try this:

C#
picturebox1.Paint += new PaintEventHandler(picturebox1_Paint);


The event arguments for the event delegate contains the graphics object for drawing the control:

C#
void picturebox1_Paint(object sender, PaintEventArgs e)
{
  Graphics c = e.Graphics;
  //the rest of your code
}


If the picture box is nested in the panel, calling the refresh on the panel will still call your picture box paint method.
 
Share this answer
 
Comments
[no name] 20-Jun-12 7:11am    
//ths will put a line on the panel1
private void panel1_Paint(object sender, PaintEventArgs e)
{


panel1.Refresh();
//here
Graphics c = panel1.CreateGraphics();
Pen red = new Pen(Color.Red, 2);
c.DrawLine(red, new Point(BeatDetector.Location.X + 5, BeatDetector.Location.Y), new Point(BeatDetector.Location.X + 5, panel1.Height));


Graphics g = panel1.CreateGraphics();
Pen black = new Pen(Color.Black, 5);
g.DrawLine(black, new Point(panel1.Width, 16), new Point(0, 16));


float[] dashValues = { 2, 5, 2, 5 };
Pen blackPen = new Pen(Color.Black, 2);
blackPen.DashPattern = dashValues;
e.Graphics.DrawLine(blackPen, new Point(panel1.Width, panel1.Height), new Point(0, panel1.Height));
}

It still flashes
Stephen Hewison 20-Jun-12 8:30am    
That's because you didn't do any of things I told you to do:

//ths will put a line on the panel1
private void panel1_Paint(object sender, PaintEventArgs e)
{


//here
Graphics c = e.Graphics;
Pen red = new Pen(Color.Red, 2);
c.DrawLine(red, new Point(BeatDetector.Location.X + 5, BeatDetector.Location.Y), new Point(BeatDetector.Location.X + 5, panel1.Height));


Pen black = new Pen(Color.Black, 5);
c.DrawLine(black, new Point(panel1.Width, 16), new Point(0, 16));


float[] dashValues = { 2, 5, 2, 5 };
Pen blackPen = new Pen(Color.Black, 2);
blackPen.DashPattern = dashValues;
c.DrawLine(blackPen, new Point(panel1.Width, panel1.Height), new Point(0, panel1.Height));
}
Stephen Hewison 20-Jun-12 8:33am    
You were using 3 different graphics objects to draw to the same component and you were calling refresh within the paint method!
[no name] 21-Jun-12 6:07am    
kk, i try that but, for some reason it keeps repainting its self, but thats not ment to happen, its meant to move when drag it and clear the last part of where i has just moved it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900