0

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;
        }
    }
}
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • You seem to have some markup for code formatting in your sample. Is that actually part of your code or an artifact from copying and pasting from somewhere else? E.g. `namespace` – Damien_The_Unbeliever Jul 31 '15 at 07:11
  • @Damien, looks like that was coming from the syntax highlighting, maybe through copy-paste. – Frédéric Hamidi Jul 31 '15 at 07:15
  • @FrédéricHamidi - I don't like to assume. If the OP genuinely has that text in their code and is struggling to communicate the issues that they're having, because it actually is there, then that's a different problem than if the markup is just a copy & paste artefact getting their question onto this site. – Damien_The_Unbeliever Jul 31 '15 at 07:18
  • Sorry, I`m working with two computers right now and the computer I am working the code on is offline. The code above is identical (after being eddited)to the code in my Offline computer. – Jimmy Yukawa Jul 31 '15 at 07:20

1 Answers1

3

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.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • Okay great its working! However, the image isnt zoomed and the middle of the magnifier form isnt showing the top of the mouse. How do I calibrate this? – Jimmy Yukawa Jul 31 '15 at 07:25
  • This is a different question, so if the following comment doesn't help, please ask a new question with that specific problem and link to this question for context. Here is my comment: In my eyes, this code simply doesn't contain anything that would magnify the image. Also, it tries to put a 300x300 pixel image into a 250x250 pixel bitmap. – Daniel Hilgarth Jul 31 '15 at 07:30
  • 1
    Okay thanks. I`ll try for a few things and ask again later on. – Jimmy Yukawa Jul 31 '15 at 07:38