Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there i would like to add a image box to my application which shows a view/picture where ever my mouse is pointing. something like windows magnifier but it must not zoom in anything it must just display in picture box what your pointer is on
Posted
Updated 21-Jan-14 19:39pm
v3
Comments
Ron Beyer 21-Jan-14 23:35pm    
Windows Forms, WPF? ASP? Mono?
Nico_Travassos 21-Jan-14 23:36pm    
Windows forms

Try following code:-
Create new form Form1

C#
//global picture box
      PictureBox objPct = new PictureBox();

      private void Form1_Load(object sender, EventArgs e)
      {
          objPct.Image = Image.FromFile(@"~\abc.png");
          objPct.Visible = false;
          this.Controls.Add(objPct);
      }

      private void Form1_MouseLeave(object sender, EventArgs e)
      {
          objPct.Visible = false;
      }

      private void Form1_MouseMove(object sender, MouseEventArgs e)
      {
          objPct.Location = new Point(Cursor.Position.X - this.Left, Cursor.Position.Y - this.Top-30);
          objPct.Visible = true;
      }
 
Share this answer
 
Comments
Nico_Travassos 22-Jan-14 0:34am    
objPct.Image = Image.FromFile(@"~\abc.png");

Why is image being imported here
Nico_Travassos 22-Jan-14 0:51am    
Does not work Error: Cannot implicity convert type "bool" to System.Windows.Forms.PictureBox
RhishikeshLathe 22-Jan-14 1:25am    
it is the path of image that u want to display on picturebox...
Use your brain man.....
Nico_Travassos 22-Jan-14 1:30am    
i am asking something like windows magnifier but it must not zoom in anything it must just display in picture box what your pointer is on
Try this,
i have updated code :-

//global picture box
        PictureBox objPct = new PictureBox();
        private void Form9_Load(object sender, EventArgs e)
        {
            objPct.Visible = false;
            this.Controls.Add(objPct);
        }
        private void Form9_MouseLeave(object sender, EventArgs e)
        {
            objPct.Visible = false;
        }
        private void Form9_MouseMove(object sender, MouseEventArgs e)
        {
            Bitmap bmp = new Bitmap(250, 200);
            Graphics g = this.CreateGraphics();
            g = Graphics.FromImage(bmp);
            g.CopyFromScreen(MousePosition.X+10, MousePosition.Y - 10, 0, 0, new Size(300, 300));
            objPct.Image = bmp;
            objPct.Location = new Point(Cursor.Position.X - this.Left, Cursor.Position.Y - this.Top - 50);
            objPct.Visible = true;
        }
 
Share this answer
 
Comments
Nico_Travassos 22-Jan-14 1:59am    
Does not work um must you not add the picture so you can view where your mouse is pointing?
RhishikeshLathe 22-Jan-14 3:58am    
this is the code for ur reference, and not solution to ur problem.
u have to do ur work by yourself.
Nico_Travassos 22-Jan-14 5:52am    
ya very helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900