Here is the tutorial for Part!
Start Solidworks and make a random part like this.
Click constraint button.
Select the body to move as the part.
Choose Mate Settings.
Select the front face.
Then Choose Top plane and coincident mate type.
Click ok and you are done.