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

Discussion in 'Microsoft Dot NET Framework Forms' started by Guest, Dec 7, 2005.

  1. Guest

    Guest 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
     
    Guest, Dec 7, 2005
    #1
    1. Advertisements

  2. "Dave Leach" <> schrieb:
    >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>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
     
    Herfried K. Wagner [MVP], Dec 7, 2005
    #2
    1. Advertisements

  3. Guest

    Guest 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

    "Herfried K. Wagner [MVP]" wrote:

    > "Dave Leach" <> schrieb:
    > >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>
    >
    > --
    > M S Herfried K. Wagner
    > M V P <URL:http://dotnet.mvps.org/>
    > V B <URL:http://classicvb.org/petition/>
    >
    >
     
    Guest, Dec 8, 2005
    #3
  4. "Dave Leach" <> schrieb:
    > 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?


    See:

    <URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/9492fe4a2b69530a>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
     
    Herfried K. Wagner [MVP], Dec 8, 2005
    #4
  5. Guest

    Guest 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

    "Herfried K. Wagner [MVP]" wrote:

    > "Dave Leach" <> schrieb:
    > > 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?

    >
    > See:
    >
    > <URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/9492fe4a2b69530a>
    >
    > --
    > M S Herfried K. Wagner
    > M V P <URL:http://dotnet.mvps.org/>
    > V B <URL:http://classicvb.org/petition/>
    >
    >
     
    Guest, Dec 9, 2005
    #5
  6. "Dave Leach" <> schrieb:
    > 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.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
     
    Herfried K. Wagner [MVP], Dec 9, 2005
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eRic

    Draw a Line on a windows form

    eRic, Oct 9, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    7
    Views:
    2,867
    Bob Powell [MVP]
    Oct 9, 2003
  2. Amil

    Determine pixel color on desktop using mouse??

    Amil, Nov 30, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    376
    Herfried K. Wagner [MVP]
    Nov 30, 2003
  3. TC

    Changing pixel color using GDI+

    TC, Mar 6, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    6
    Views:
    1,889
    Morten Wennevik
    Mar 7, 2005
  4. Mark Gaeth

    Drawline on Form at runtime with mouse?

    Mark Gaeth, Mar 11, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    709
    Guest
    Mar 15, 2005
  5. A.M-SG

    Draw a horizontal line on the form without using GDI

    A.M-SG, Jan 16, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    6
    Views:
    697
    Guest
    Jan 17, 2006
Loading...

Share This Page