I don't know why it would go behind sometimes, but I have seen behavior like this before. Could you add some code to always bring it to the front? You could use the BringWindowToTop API.