I had this issue and the thing that fixed was going to my steam folder, then finding tf2 (Steam > steamapps > common > Team Fortress 2) then find hl2.exe, right click on it, click on properties, go to the compatibility tab and check the box that says "Disable fullscreen optimizations" then apply that change.
You could also try this with other games by finding their respective .exe and disabling it if it is an option.
Note: I'm on windows 10 and I don't know if this option is also on 8.1 or 7.