Stay on screen extension

I know that I can draggable the object to a certain distance in length and width BY " STAY ON SCREEN "extension. But how can I draggable the movement of an object at an angle to a certain distance?