How to duplicate a screen to a second screen in C#

I had the need to have a small program that displays all that i can see on my main screen in the secondary screen that is attached to my computer

I have 2 screen , the second screen extends the first screen and it is located in the following coordinates: 1025,769 ( meaning it is located on the right-bottom side

The idea behind the program is simple , capture the main screen display every few milliseconds and take the image that was captured and draw it on the secondary display

So i create a windows application project, on the form that is created i put a picture box control that fills all the space of the form (use Dock=Fill)

When the application is activated the position of this form is placed on the second display area and the picture/image of the first display will be painted on it

The start position of this form is set manually to the location of the second display (so use "StartPosition=Manual"

This is the code that creates a timer that will tick in order to copy the display every 100 milliseconds

private Timer duplicateScreenTimer;

public DuplicateApp()
{
duplicateScreenTimer = new Timer();
duplicateScreenTimer.Interval = 100;
duplicateScreenTimer.Tick += new
EventHandler(getImage);
}

This is the function that is called every time the timer ticks. Note that in this function i use:
1. An external class to capture the display of the main display
2. i add a mouse pointer to the image in order that on the second display we will see a mouse pointer. The mouse pointer is actually a bitmap image that can be replaced


private void getImageHelper()
{
//get the x,y location of the mouse
int x = System.Windows.Forms.Control.MousePosition.X;
int y = System.Windows.Forms.Control.MousePosition.Y;

//get the image of the main display
Bitmap desktopImage = CaptureScreen.GetDesktopImage();

Graphics gra = Graphics.FromImage(desktopImage);

//add the mouse cursor on the image that we want to use on the other display
gra.DrawImage(mouseImage, new Point(x - (mouseImage.Width / 2) + 5, y));

//set the new image on the picture box
pictureBox.Image = desktopImage;
}

The bitmap image is an image that must be located at the same folder of the application. It is loaded and made transparent in order to fit nicely on the image that is passed to the second display


private Bitmap mouseImage;
mouseImage = (Bitmap)Bitmap.FromFile("pointer.bmp");
mouseImage.MakeTransparent();