Draw a single pixel on Windows Forms

Mark T picture Mark T · Apr 17, 2009 · Viewed 97.7k times · Source

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

Henk Holterman picture Henk Holterman · Apr 17, 2009

This will set a single pixel:

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