Click here to Skip to main content
Rate this: bad
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 1:40am
Edited 23-Nov-12 2:15am
Rate this: bad
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 
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
Please Sign up or sign in to vote.

Solution 2

Try this:
            Region r = new Region(myPictureBox.Size);
            GraphicsPath elipse = new GraphicsPath();
            if (r.IsVisible(point))
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 Peter Leow 375
1 Sergey Alexandrovich Kryukov 280
2 Zoltán Zörgő 258
3 CHill60 195
4 TheRealSteveJudge 180
0 Sergey Alexandrovich Kryukov 8,853
1 OriginalGriff 6,631
2 Peter Leow 4,102
3 Zoltán Zörgő 3,714
4 Kornfeld Eliyahu Peter 2,525

Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2015
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