The first step would be to create the Graphics object to work for the drawing. You cannot draw directly, you are required to create a Bitmap, and use the Graphics object to create different things on it.
You can create your own Bitmap, by passing your pictureBox (Image) to it, and make the Graphics by it. Like this,
Graphics gr = Graphics.FromImage(bitmap);
.. now gr would be the actual graphics, that would represent the bitmap of your image and you can now work on it. You can draw different shapes on it.
To draw a simple Rectangle you are required to call
DrawRectangle()
function.
gr.DrawRectangle(pen, rect);
.. now it will have the rectangle on it, add this (
updated) instance of the Bitmap to the PictureBox to show it on the screen or just save it.
As Bill has mentioned in the comments, I would like to add that piece of information to my answer. It is a good approach to add shapes to the graphics object for the image in the
Paint Event[
^]. Paint event is raised when you're going to add shapes to the control for rendering; trust me there is no painter involved. You can simply just attach an event handler to the control like you do for the Click event.
Example code for the Paint Event handler is in the link I attached.
Entire directory for all of the methods of the Graphics object can be found
here[
^].