Hi all,
Once I started learning C#, really much enjoying it. I faced some problem using GUI. I m trying to draw ellipse as many as possible with mouse moving events, but theres problem....
My code here:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
myRect.Width = 0;
myRect.Height = 0;
myRect.X = e.X;
myRect.Y = e.Y;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 2);
if (e.Button == MouseButtons.Left)
{
g.Clear(this.BackColor);
myRect.Width = e.X - myRect.X;
myRect.Height = e.Y - myRect.Y;
g.DrawEllipse(p, myRect);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Green,4);
g.DrawEllipse(p, myRect);
// g.Dispose();
}
If you run this code, it works fine. BUT I cant draw ellipse continually, then only last one remains and previous one is deleted. BUT if I removeg.Clear(this.BackColor);
this line from mouseMove event, then I can draw ellipse as many as possible. But process shows shadow of the drawing which I want to remove. If you run both ways you might understand what Im trying to do.......
Pls help, urgent pls
thanks in advance
bagi