像图像放大镜一样的图像框中的鼠标视图 [英] Mouse view in imagebox like windows magnifier

查看:74
本文介绍了像图像放大镜一样的图像框中的鼠标视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在我的应用程序中添加一个图像框,显示我的鼠标指向的视图/图片。类似于Windows放大镜的东西,但它不能放大任何东西它必须只在图片框中显示你的指针在哪里

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

推荐答案

尝试以下代码: -

创建新表单Form1



Try following code:-
Create new form Form1

//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;
      }


试试这个,

i有更新代码: -



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;
        }


这篇关于像图像放大镜一样的图像框中的鼠标视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆