The coordinate system As we all know, drawing systems in .Net are based upon pixels that are arranged on a two-dimensional coordinate system. The origin, that is, the points (0, 0) lie on the far top-left of the screen. Each consecutive pixel towards the right of the origin forms the x-axis, and each consecutive pixels towards the bottom of the screen forms the y-axis. If you note carefully, the co-ordinate system for onscreen graphics is an inverted copy of the Cartesian Co-ordinate System used in Mathematical Geometry. Now, when we give the call to the system to draw a rectangle, we provide it with four arguments. The x-coordinate, the y-coordinate, width and the height of the rectangle. We will traverse through each step that the system undergoes to create a rectangle. Step 1: First, the point (x, y) or the pixel present on the point (x, y) is plotted or marked on the coordinate system as shown below. Step 2: Then, it adds the width provided as argument to the next consecutive x-coordinate. For instance, if the x-coordinate is 0 and the width is 10, then the resultant point on the x-axis (fx) will be:
Because x-coordinate specified was 0,
So the next x-coordinate will be 1
Final Point = next x-coordinate + width
Final Point = 1 + 10
Final Point = 11;
Same goes for the y-coordinate and the height to calculate the resultant point on the y-axis (fy). Step 3: System marks all the pixels from (0, 0) to the point (fx, 0) on the x-axis and also marks all the pixels from (0, 0) to (0, fy). This gives two straight lines joined at (0, 0) at an angle of 90 degrees. The points (fx, 0) and (0, fy) are then interconnected at the point (fx, fy). Thus giving the illusion of a perfect rectangle. What happens with GDI+ drawing routines If you keep the x-coordinate and the y-coordinate as (0, 0), then it is seen that: Resultant Point fx = width + 1 and Resultant Point fy = height + 1 So, if we specify the below mentioned statements in GDI+:
g.DrawRectangle(new SolidBrush(Color.Blue), 0, 0, this.Width, this.Height);
g.DrawRectangle(new SolidBrush(Color.Blue),
new Rectangle(0, 0, this.Width, this.Height));
From these statements, it is clear that the resultant point to which the rectangle will be stretched is (this.Width+1, this.Height+1) which unfortunately exceeds the visible region of the Component or Custom Control. Did not understand a single word? Ask for a detailed and illustrated