Try this... Create a new (C# windows) project and put this code in the form
cs file:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ExempleGraphique
{
public partial class Form1 : Form
{
Point MyCircleCenter = new Point(100, 50);
Size MyCircleRay = new Size(75, 75); // Must be the same values to generate
a circle.
public Form1() { InitializeComponent(); }
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(this.BackColor);
base.OnPaint(e);
// Drawing Circle contained in x=0-150 & y=0-150
// Said simply: center = 75,75, ray=75
Rectangle MyCirclePosition = new Rectangle(
MyCircleCenter.X - MyCircleRay.Width/2,
MyCircleCenter.Y - MyCircleRay.Height/2,
MyCircleRay.Width,
MyCircleRay.Height);
g.DrawEllipse(Pens.Red, MyCirclePosition);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
// If distance from center is higher than circle ray, it's outside the
circle.
Boolean IsInCircle = (
(e.X - MyCircleCenter.X) * (e.X - MyCircleCenter.X) +
(e.Y - MyCircleCenter.Y) * (e.Y - MyCircleCenter.Y) )
< (MyCircleRay.Height * MyCircleRay.Width /4);
if (IsInCircle) { txtMessage.Text = "In the cercle"; }
else { txtMessage.Text = "Out of the cercle"; }
}
}
}
<bk> a écrit dans le message de news:
%2****************@TK2MSFTNGP04.phx.gbl...
Hello C-Sharpers,
Lets say i have a UserControl which draws a circle of radius r at
co-ordinates x,y. How can i tell if the cursor is currently inside or
outside of the circle?
thank you,
bk