How to get the color of a pixel of a Panel
(or anything else, such as a Form
)?
(Can I do it with Graphics
's functions?)
Thank you in advance.
How to get the color of a pixel of a Panel
(or anything else, such as a Form
)?
(Can I do it with Graphics
's functions?)
Thank you in advance.
Based on the code provided here,
I created an extension method that returns the color of a control pixel, given the client coordinates of the pixel:
public static class ControlExts
{
public static Color GetPixelColor(this Control c, int x, int y)
{
var screenCoords = c.PointToScreen(new Point(x, y));
return Win32.GetPixelColor(screenCoords.X, screenCoords.Y);
}
}
So, in your case you can do:
var desiredColor = myForm.GetPixelColor(10,10);