手机版
你好,游客 登录 注册
背景:
阅读新闻

C#中利用鼠标的坐标进行截图

[日期:2013-10-07] 来源:Linux社区  作者:w329636271 [字体:大 中 小]

C#中利用鼠标的坐标进行截图

private void Form1_Click(object sender, EventArgs e)
        {

            if (flag % 2 == 0)
            {
                Fx = Cursor.Position;//获取在控件中的鼠标坐标 这个就是屏幕的坐标了
                this.textBox1.Text = string.Format("{0},{1},{2},{3}", Fx.X, Fx.Y, Fy.X, Fy.Y);
            }
            else
            {
              // Fy = this.PointToScreen(Cursor.Position);
                //MessageBox.Show(string.Format("{0},{1},{2},{3}",Fx.X,Fx.Y,Fy.X,Fy.Y));

                Fy = Cursor.Position;
              //  this.textBox1.Text = string.Format("{0},{1},{2},{3}", Fx.X, Fx.Y, Fy.X - Fx.X, Fy.Y-Fx.Y);
                this.textBox1.Text = string.Format("{0},{1},{2},{3}", Fx.X, Fx.Y, Fy.X, Fy.Y);
                int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
                int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
                Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);  // the final image used by memory reference
                Graphics gfx = Graphics.FromImage((Image)bmpScreenShot); //获取绘图绘画
                // gfx.CopyFromScreen(this.pictureBox1.PointToScreen(this.pictureBox1.Location), new Point(0, 0), this.pictureBox1.Size);
                //gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));//获取整个屏幕的类似printscreen
              // Cursor.Position = new Point(Fx.X + 100, Fx.Y + 100);
                gfx.CopyFromScreen(Fx.X, Fx.Y, 0, 0, new Size(Fy.X-Fx.X, Fy.Y-Fx.Y));//从这个屏幕中截取我们所需要的部分
                this.imageBox1.BackgroundImage = bmpScreenShot;
                bmpScreenShot.Save("shot.png");
            }
          // MessageBox.Show("OK");
            flag++;
        }

推荐阅读:

Linux下C语言实现多线程文件复制 http://www.linuxidc.com/Linux/2013-03/81373.htm

在Win32下用C++实现多线程读写锁 http://www.linuxidc.com/Linux/2013-01/78583.htm

Linux多进程多线程互斥同步例子 http://www.linuxidc.com/Linux/2013-01/78394.htm

Linux下多线程通过蒙特卡洛法来求取pi值 http://www.linuxidc.com/Linux/2013-01/77956.htm

C++中使用模板传递函数类型 http://www.linuxidc.com/Linux/2012-11/73809.htm

linux
相关资讯       C# 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款