Click here to Skip to main content
12,450,771 members (46,116 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Dear friends,

I have created an ellipse over picture box , now I want when I click on picture box it should tell weather I have clicked "Inside" defined ellipse or "Outside".

Please friends help me..

I want to do this on PictureBox_MouseClick() event.....

My paint event code is below.

private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Color c1 = Color.FromArgb(50, Color.Green);
            foreach (Rectangle rect in listRect)
            {
                using (Pen pen = new Pen(Color.Red, 2))
                {
                    e.Graphics.DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    e.Graphics.FillEllipse(new SolidBrush(c1), rect.X, rect.Y, rect.Width, rect.Height);
                   
                }
            }           
        }
Posted 23-Nov-12 0:40am
Updated 23-Nov-12 1:15am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you can do one simple trick in case if the picturebox background for example is white and the eclipse is green , so you can play in that by getting the color of the point clicked and compared if it is green or not ...
PictureBox_MouseClick(object j,eve.... e){
 
Color colorAtPoint = img.GetPixel(e.x, e.y);
 // check if color == green 
}

Regards...
  Permalink  
Comments
Ajit Kumar Pal 23-Nov-12 23:44pm
   
I have an color image in background which may vary also,,then how could I compare ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try this:
Region r = new Region(myPictureBox.Size);
GraphicsPath elipse = new GraphicsPath();
elipse.AddEllipse(rect);
r.Union(elipse);
if (r.IsVisible(point))
    {
    ...
    }
  Permalink  
Comments
Ajit Kumar Pal 24-Nov-12 0:02am
   
Region is not considering (picturebox.size)?
Ajit Kumar Pal 24-Nov-12 1:07am
   
Thanks buddy I got it right..Thank you vary much
OriginalGriff 24-Nov-12 2:36am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100