Before moving the horizontal line compare its "start coordinate to be" Y value with the Y value of one of the vertical lines. If it would be outside the range the vertical lines define, don't move the horizontal line.