Weird GDI+ rectangle drawing
-
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
-
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
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 -
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