PC Review


Reply
Thread Tools Rate Thread

drawing on a panel

 
 
dk60
Guest
Posts: n/a
 
      31st Dec 2009
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.
 
Reply With Quote
 
 
 
 
mick
Guest
Posts: n/a
 
      1st Jan 2010

"dk60" <(E-Mail Removed)> wrote in message news:85d580d8-3ff9-4f43-87e0-(E-Mail Removed)...
> 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.


You can use this to get the local coords

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

mick
 
Reply With Quote
 
mick
Guest
Posts: n/a
 
      1st Jan 2010

"mick" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...

"dk60" <(E-Mail Removed)> wrote in message news:85d580d8-3ff9-4f43-87e0-(E-Mail Removed)...
> 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.


You can use this to get the local coords

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

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

Graphics g = panel1.CreateGraphics();

mick
 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      1st Jan 2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I clear a panel from old drawing Tony Johansson Microsoft C# .NET 1 21st Apr 2011 11:34 PM
Drawing on a panel Chris S. Microsoft C# .NET 2 23rd Mar 2006 02:49 PM
Panel drawing problem jon morgan Microsoft Dot NET Framework Forms 2 6th Jun 2005 03:18 PM
Panel drawing problems. Leif Eirik Olsen Microsoft C# .NET 2 23rd May 2005 03:31 PM
drawing on a panel Saso Zagoranski Microsoft Dot NET Compact Framework 4 17th Feb 2004 08:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:16 PM.