UserControl ClientRectangle is smaller than it say

2019-08-26 21:36发布

问题:

I am trying to make my UserControl with custom borders (I changed default border style to "none" in properties - I created control and I am invoking Graphics.DrawRectangle(...,ClientRectangle). And what I see is only the top and left borders of my painted rectangle - it seems that real size of the area where I can draw is different than ClientRectangle... How to change it / get the right ClientRectangle size?

回答1:

ClientRectangle returns the rectangle in exclusive coordinates so you need to subtract 1 from the bottom and right hand sides. This will work regardless of how many units per pixel there are in the current graphics mode, someone correct me if I am wrong.