L
L
Looking2015-10-21 20:53:18
C++ / C#
Looking, 2015-10-21 20:53:18

How to determine the color of a pixel on a form?

Greetings. Unable to determine the color of the clicked pixel.
The figure itself is drawn in this way:

SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
            Graphics formGraphics;
            formGraphics = this.CreateGraphics();
            formGraphics.FillEllipse(myBrush, new Rectangle((int)drawX, (int)drawY, figW, figH));

I need to determine that they clicked on it.
If you do as in this answer stackoverflow.com/questions/753132/how-do-i-get-th... it will output the background color of the form, not the shape.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-10-22
@Nipheris

1) if you want to check that you clicked on a shape - better do it using the ellipse equation;
2) if you still need the color of a pixel, it's better to do all the rendering in a separate Bitmap, then display it on the form (using the Image control, for example), and then read the color FROM IT when you click on the control. So there will be fewer surprises than bothering with the screen;
3) pay close attention to whether the coordinates you are working with are relative to the corner of the screen, the form, or the client area of ​​the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question