How to draw a 1 pixel long line using Graphics.DrawLine?

G

Guest

I am writing a Windows Forms application graphing routine using VS.NET 2003,
Visual C# and .NET Framework 1.1.

The Graphics.DrawLine(Pen,int,int,int,int) method seems to work okay unless
the desired line being drawn is only one pixel long (horizontally). I have
not found a way to get a horizontal line of only one pixel to be drawn. I
either get no line or a two pixel line.

Example method calls:

Graphics.DrawLine( Pen, 20, 50, 21, 50 ); // Results in two pixel long line.
Graphics.DrawLine( Pen, 20, 50, 20, 50 ); // Results in no pixels being
drawn.

So how do I get a one pixel long line?

Thanks,
Dave
 
H

Herfried K. Wagner [MVP]

Dave Leach said:
I am writing a Windows Forms application graphing routine using VS.NET
2003,
Visual C# and .NET Framework 1.1.

The Graphics.DrawLine(Pen,int,int,int,int) method seems to work okay
unless
the desired line being drawn is only one pixel long (horizontally). I
have
not found a way to get a horizontal line of only one pixel to be drawn. I
either get no line or a two pixel line.

<URL:http://www.bobpowell.net/single_pixel_lines.htm>
 
G

Guest

The link provided in the reply below deals with line width. I am asking how
to make a line 1 pixel in LENGTH. We are already able to draw lines that are
one pixel wide.

So again, the issue is how to draw a line that is one pixel in length?

Dave
 
G

Guest

If this is how a 1 pixel "line" is drawn does no one else think that the
Graphics.DrawLine method is defective? Shouldn't the method support drawing
lines from 1 to N pixels in length?

Dave
 
H

Herfried K. Wagner [MVP]

Dave Leach said:
If this is how a 1 pixel "line" is drawn does no one else think that the
Graphics.DrawLine method is defective? Shouldn't the method support
drawing
lines from 1 to N pixels in length?

'DrawLine' doesn't draw n pixels, it draws n units.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top