How to make a mouselock script

I was wondering how I would go about making a mouselock script in C#, for my FPS. It would be awesome if it could be toggled in a way so that you could still use GUIs.

Screen.lockCursor = true;