#1 typically works well, #2 can have problems if the font is not fixed-pitch because space may be narrower than some characters. You can also draw a solid-color box in the background color that covers the area needed for the largest text - usually slower than method #1, but does not require knowing what the previous text was.