Jimmy Yukawa
Jimmy Yukawa

Reputation: 13

Creating a screen magnifier in C#

I followed this website to make a magnifier in C#. http://www.ultimateprogrammingtutorials.info/2013/03/how-to-make-simple-magnifier-in-c.html However after debugging it in visual studio all i get is a blank form. Did I do something wrong or there something wrong with the code?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Magnifier
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Graphics g;
        Bitmap bmp;

        private void Timer1_Tick(object sender, EventArgs e)
        {
            bmp = new Bitmap(250, 200);
            g = this.CreateGraphics();
            g = Graphics.FromImage(bmp);
            g.CopyFromScreen(MousePosition.X - 100, MousePosition.Y - 10,
                0, 0, new Size(300, 300));
            PictureBox1.Image = bmp;
        }
    }
}

Upvotes: 0

Views: 2652

Answers (2)

Trevor Loughlin
Trevor Loughlin

Reputation: 1

Apart from setting the timer tick, make sure to enable the timer!

Upvotes: 0

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174329

You don't just need to copy and paste the code from the website, you additionally need to add a timer component to your form and bind its Tick event to your Timer1_Tick method.

Upvotes: 3

Related Questions