   Scrolling a grid with minimal redraw
  I'm having a generic brainfart at the moment, in that I've managed to completely screw up my grey matter with a pretty trivial problem. I have a regular grid, defined by:fGridResolution (in pixels)fGridZoom (factor)fScrollX/Y (floating point unit-based parameters which define 1.0 as one grid cell)fGridFactor = fGridResolution * fGridZoom (just a shorthand)For each update I'm creating an rc, which is the update rectangle in work area coordinates. I'm using ScrollWindowEx() to scroll the work area and minimal redraw to regenerate the part of the work area that is scrolled into view.I'm failing at getting my grid to line up:fGridXMin = (rc.left + fmod(fScrollX, 1.0) * fGridFactor);iNumCells = (int)((rc.right - rc.left) / (TReal)fGridFactor);for(TReal _x = fGridXMin; i <= iNumCells; i++)  {  GDI::DrawLine(dc, (int)_x, rc.top, (int)_x, rc.bottom, editor->clrGrid, 1);  _x += fGridFactor;  }The above code draws the grid properly if the scroll speed is less than one grid cell size, but causes it to become messed up when the increment is greater than one grid cell size. I've been staring at this code for way too long now, trying to cloudbust the heck out of it, but my brain is simply not willing to cooperate.If anyone can see what the flaw here is, I'd appreciate it a whole bunch :).   
  Off the top of my head, it just looks like some confusion involving relative motion.  The scrolling to the right (+X) produces a relative left motion in the grid (-X).  So when you're dealing with fScrollX/Y to draw the grid, you need to invert your thinking.  Try (1.0 - fmod(fScrollX, 1.0)) instead of just the fmod and see if that helps at all.   ;  Thank you! That was half of the problem (the other half was the initial alignment of the grid lines, which requires another adjustment) - but it seems to be working now! I hate it when these little things come along...   