There is a DesignMode property that you can check but in my experience it's not always accurate. You could also check to see if the executable is DevEnv.exe
Take a look here. Might make this question a dup but it all depends on what you're trying to accomplish.