Headlights go on and off when engine is hot

I replaced the dash light switch today. I hope that solves the problem. Now my dash lights up better too.

I want to THANK ALL OF YOU for your help.