Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Line with different width have different lengths?

Line with different width have different lengths?

Scheduled Pinned Locked Moved .NET (Core and Framework)
graphicsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KeesVer
    wrote on last edited by
    #1

    Given the code below, the first line is drawn 1 pixel longer than the second line (any line where width > 1 is drawn 1 pixel short). Any idea what might be causing this or is this normal behavior? Pen p = new Pen(Color.Black, 1); e.Graphics.DrawLine(p, 10, 10, 10, 100); p = new Pen(Color.Black, 2); e.Graphics.DrawLine(p, 14, 10, 14, 100); p.s. The same thing happens when drawing horizontal lines. Kees

    L 1 Reply Last reply
    0
    • K KeesVer

      Given the code below, the first line is drawn 1 pixel longer than the second line (any line where width > 1 is drawn 1 pixel short). Any idea what might be causing this or is this normal behavior? Pen p = new Pen(Color.Black, 1); e.Graphics.DrawLine(p, 10, 10, 10, 100); p = new Pen(Color.Black, 2); e.Graphics.DrawLine(p, 14, 10, 14, 100); p.s. The same thing happens when drawing horizontal lines. Kees

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      that is the normal behavior: the pen moves the way you ask it to move; when its size exceeds one, it will hit some pixels before and after the intended trajectory since a pen by default has a circular shape. I guess you can modify both the pen characteristics and the way lines are drawn though, if you really need to. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        that is the normal behavior: the pen moves the way you ask it to move; when its size exceeds one, it will hit some pixels before and after the intended trajectory since a pen by default has a circular shape. I guess you can modify both the pen characteristics and the way lines are drawn though, if you really need to. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        K Offline
        K Offline
        KeesVer
        wrote on last edited by
        #3

        Thanks Luc, Setting EndCap and StartCap to LineCap.Square solved it. Kees

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups