In this paper we propose a novel approach to the detection of on-line handwritten text lines based on dynamic programming. We try to find the paths with the minimum cost between two consecutive text lines. Most steps of the proposed algorithm are based on off-line information. Hence the method can also be applied to off-line documents after a few minor changes. In our experiments we show that this dynamic programming based approach is better than a common on-line segmentation procedure.