Click here to Skip to main content
Rate this: bad
good
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
Edited 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 at 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 at 24-Nov-12 0:02am
   
Region is not considering (picturebox.size)?
Ajit Kumar Pal at 24-Nov-12 1:07am
   
Thanks buddy I got it right..Thank you vary much
OriginalGriff at 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
0 Gihan Liyanage 392
1 ClimerChinna 247
2 Sergey Alexandrovich Kryukov 225
3 vikinghunter 176
4 OriginalGriff 161
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
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