Search code examples
c#.netwinformsgdi+pixel

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#.


Solution

  • This will set a single pixel:

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