It does not work, because Pixel++ assumes that next pixel to fill follows in memory directly afterwards. Which is not true if x != 0 or width != bitmap width.
Here's an illustration (4x4 image):
If you ask to drawRectangle with x=1, y=1, width=1, height=2, then it should fill only F and J values.
Initially you calculate Row to point to F pixel (line 22).
Then you assign Pixel pointer to same value (line 28).
Now in you do Pixel++ so it will point to G (line 31).
In case you do Row += Pitch, it will now go from F to J pixel correctly. Because Row from F pixel + Pitch is J pixel.
But in case you reuse Pixel value in next loop iteration, it will fill G pixel.
To better understand how values change, I strongly recommend you to use debugger
. Set up watch window to show values of variables (Row, Pixel, Pitch, x, y, ...) and step line by line over small example (1x2 rectangel) and see how values are changing.