On 12/31/2009 3:47 PM, dk60 wrote:
> when I draw an ellipse on a panel on a form the ellipse actually gets
> drawn behind the panel, so that the panel covers it. Is there a way to
> draw graphics inside a panel, or some other control, so that the panel
> serves as a canvas, and the mouse coordinates are relative to the
> panel? even if I use the panel MouseMove event the coordinated of e
> are still relative to the form and not relative to the panel.
It sounds like you are handling the forms paint event handler rather
than the panels paint handler. You want to handle the panel's paint
event as follows:
public Form1()
{
InitializeComponent();
panel1.Paint += new PaintEventHandler(panel1_Paint);
}
void panel1_Paint(object sender, PaintEventArgs e)
{
Pen p = Pens.Black;
Point loc = new Point (0, 0);
Size s = new Size(12, 15);
Rectangle r = new Rectangle(loc, s);
e.Graphics.DrawEllipse(p, r);
}
--
Mike
|