确定在鼠标单击上的惠点位于定义的椭圆内 [英] Determine on mouseclick wheather point lies inside an defined ellipse

查看:71
本文介绍了确定在鼠标单击上的惠点位于定义的椭圆内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我已经在图片框上创建了一个椭圆,现在我想当我单击图片框时应该告诉天气我单击了内部" 定义的椭圆或外部" . br/>
请朋友帮我..

我想在PictureBox_MouseClick()事件上执行此操作.....

我的绘画事件代码如下.

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);
                   
                }
            }           
        }

推荐答案

如果图片框背景为白色,而月食为绿色,则可以做一个简单的技巧,因此您可以在其中使用通过获取点击的点的颜色并进行比较来比较该点是否为绿色...
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...


尝试一下:
Try this:
Region r = new Region(myPictureBox.Size);
GraphicsPath elipse = new GraphicsPath();
elipse.AddEllipse(rect);
r.Union(elipse);
if (r.IsVisible(point))
    {
    ...
    }


这篇关于确定在鼠标单击上的惠点位于定义的椭圆内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆