Mark T Mark T - 1 month ago 24
C# Question

Draw a single pixel on Windows Forms

I'm stuck trying to turn on a single pixel on a Windows Form.

graphics.DrawLine(Pens.Black, 50, 50, 51, 50); // draws two pixels

graphics.DrawLine(Pens.Black, 50, 50, 50, 50); // draws no pixels


The API really should have a method to set the color of one pixel, but I don't see one.

I am using C#.

Answer

This will set a single pixel:

e.Graphics.FillRectangle(aBrush, x, y, 1, 1);
Comments