Rectange Size

  • Thread starter Thread starter Fred West
  • Start date Start date
F

Fred West

I create a user control with width = 200 pixels and height = 200 pixels. I
create a paint event handler to draw a rectangle around its edges. I define
a Rectangle as follows:

Rectangle r = new Rectangle(0,0,200,200);

I then draw it in my event handler as follows:

dc = e.Graphics;
dc.DrawRectangle(mypen,r);


BUT the right and bottom edges are clipped! I would expect that since my
blank user control has the same size it should fit perfectly in side. If I
define my rectangle as

Rectangle r = new Rectangle(0,0,199,199);

then all is well. Do I interpret this to mean that height and width for the
rectangle refer to the white space inside and not its border. Any comments
are appreciated.

- Fred using VS2003 (C# .Net)
 
Hi,

This is just the way the DrawRectangle method works.

The sides of the rectangle itself are at least a pixel wide. The top/left sides
are included in the width/height, but the bottom/right sides extend beyond the
specified width/height.

So if you specify a width/height of 3 you would get

xxxx
x x
x x
xxxx

with a 2 you get:

xxx
x x
xxx

and with a 1 you get:

xx
xx

Hope this helps.

Best regards,

Rodger

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>
 
Back
Top