Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

drawing on a panel

0 views
Skip to first unread message

dk60

unread,
Dec 31, 2009, 3:47:07 PM12/31/09
to
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.

mick

unread,
Jan 1, 2010, 3:32:24 PM1/1/10
to

"dk60" <danny...@gmail.com> wrote in message news:85d580d8-3ff9-4f43...@k23g2000yqa.googlegroups.com...

You can use this to get the local coords

Point localMousePosition = panel1.PointToClient(Cursor.Position);

mick

mick

unread,
Jan 1, 2010, 3:48:27 PM1/1/10
to

"mick" <cough...@privacy.com> wrote in message news:%23BmvJGy...@TK2MSFTNGP05.phx.gbl...

Point localMousePosition = panel1.PointToClient(Cursor.Position);

Also, when you create your Graphics object are you using something
like this

Graphics g = panel1.CreateGraphics();

mick

Family Tree Mike

unread,
Jan 1, 2010, 4:23:26 PM1/1/10
to

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

0 new messages