S
shijin_zu
Is there a difference between the Graphics object that comes with the Paint
event and the Graphics object that is obtained by Graphics g =
CreateGraphics();?
In a custom control that I'm creating, I noticed that the same line drawn
inside OnPaint() is not exactly the same as the one drawn by my own method
Update(). In the Update() method I tried to replace the same line with a
different color, but there are always some leftover pixels by the original
Black pen and they can't be completed "erased" by the new the Red pen. Here
is my simplified code:
public class myControl : System.Windows.Forms.Control
{
.......
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
// draw this line with Black
e.Graphics.DrawLine(m_pen1, 10, 10, 50, 50);
return;
}
Public void Update()
{
Graphics g = CreateGraphics();
// draw this line with Red pen
g.DrawLine(m_pen2, 10, 10, 50, 50);
g.Dispose();
}
}
Any insights to the situation?
Thanks,
Shijin
event and the Graphics object that is obtained by Graphics g =
CreateGraphics();?
In a custom control that I'm creating, I noticed that the same line drawn
inside OnPaint() is not exactly the same as the one drawn by my own method
Update(). In the Update() method I tried to replace the same line with a
different color, but there are always some leftover pixels by the original
Black pen and they can't be completed "erased" by the new the Red pen. Here
is my simplified code:
public class myControl : System.Windows.Forms.Control
{
.......
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
// draw this line with Black
e.Graphics.DrawLine(m_pen1, 10, 10, 50, 50);
return;
}
Public void Update()
{
Graphics g = CreateGraphics();
// draw this line with Red pen
g.DrawLine(m_pen2, 10, 10, 50, 50);
g.Dispose();
}
}
Any insights to the situation?
Thanks,
Shijin