Small disclaimer: This is my first time messing with Graphics in Forms, therefore I am not so familiar with the concepts here
Alright, so I have been trying to make an application that tracks the cursor's position in the entire screen and draws an Ellipse around it. The code I borrowed was from this question (I changed the X and Y position of the Ellipse in order to auto-adjust itself around the cursor regardless of its size) everything works perfectly up to this point. Here is the code so far:
public static float width;
public static float height;
public Main(float w, float h)
{
InitializeComponent();
this.DoubleBuffered = true;
width = w;
height = h;
BackColor = Color.White;
FormBorderStyle = FormBorderStyle.None;
Bounds = Screen.PrimaryScreen.Bounds;
TopMost = true;
TransparencyKey = BackColor;
this.ShowInTaskbar = false;
timer1.Tick += timer1_Tick;
}
Timer timer1 = new Timer() { Interval = 1, Enabled = true };
protected override void OnPaint(PaintEventArgs e)
{
DrawTest(e.Graphics);
base.OnPaint(e);
}
private void DrawTest(Graphics g)
{
var p = PointToClient(Cursor.Position);
g.DrawEllipse(Pens.DeepSkyBlue, p.X - (width / 2), p.Y - (height / 2), width, height);
}
private void timer1_Tick(object sender, EventArgs e)
{
Invalidate();
}
So now I want the application to check whether a preassigned color is present within the area of the Ellipse, and if so, get the position of the nearest pixel to the cursor that has this color. I have searched everywhere and haven't found any method of doing it.
I get that the logic behind it would be to get all the pixels within the Ellipse, check if the color exists and find the one pixel with this color nearest to the cursor but I haven't been able to implement it.
Any help would be very appreciated.