I think this needs to be done before the comparison?  Otherwise `SetText("\nfoo\n");` called twice will in both cases invalidate the textbox which isn't necessary.