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. C#
  4. Weird GDI+ rectangle drawing

Weird GDI+ rectangle drawing

Scheduled Pinned Locked Moved C#
graphicsquestionwinforms
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, why does this code produce a rectangle 6x6 (seen by zooming on a screen capture) ? Pen pen = new Pen(Color.FromArgb(255,0,0),1); pen.Alignment = PenAlignment.Inset; // Same with center graphics.DrawRectangle(pen,10,10,5,5); It gives : ****** *====* *====* *====* *====* ****** (* means a red pixel, = means a background pixel) If I give a width of 2, then the red rectangle is correctly drawn in a 5x5 pixels rectangle. Thanks Nicolas

    J 1 Reply Last reply
    0
    • L Lost User

      Hi, why does this code produce a rectangle 6x6 (seen by zooming on a screen capture) ? Pen pen = new Pen(Color.FromArgb(255,0,0),1); pen.Alignment = PenAlignment.Inset; // Same with center graphics.DrawRectangle(pen,10,10,5,5); It gives : ****** *====* *====* *====* *====* ****** (* means a red pixel, = means a background pixel) If I give a width of 2, then the red rectangle is correctly drawn in a 5x5 pixels rectangle. Thanks Nicolas

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Charles Petzold pointed this out in his Programming Microsoft Windows with C# book so I assume it is a known issue. I don't think anything will be done about it though because to change it would break a lot of code at the source level (side by side versioning protects already built binaries but alas, it doesn't protect source level breaking). I'm not sure why a pen with width of 2 would change that, unless the alignment is what is causing it. BTW if you want a red pen of width 1 you could just use Pen pen = Pens.Red; :) James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

      L 1 Reply Last reply
      0
      • J James T Johnson

        Charles Petzold pointed this out in his Programming Microsoft Windows with C# book so I assume it is a known issue. I don't think anything will be done about it though because to change it would break a lot of code at the source level (side by side versioning protects already built binaries but alas, it doesn't protect source level breaking). I'm not sure why a pen with width of 2 would change that, unless the alignment is what is causing it. BTW if you want a red pen of width 1 you could just use Pen pen = Pens.Red; :) James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks a lot for the useful information. I find incredible that such a bug exists and it won't be corrected. Nicolas

        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