Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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
Updated 23-Nov-12 1:15am
v3

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 ...
C#
PictureBox_MouseClick(object j,eve.... e){

Color colorAtPoint = img.GetPixel(e.x, e.y);
 // check if color == green 
}


Regards...
 
Share this answer
 
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 ?
Try this:
C#
Region r = new Region(myPictureBox.Size);
GraphicsPath elipse = new GraphicsPath();
elipse.AddEllipse(rect);
r.Union(elipse);
if (r.IsVisible(point))
    {
    ...
    }
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900