C#截图

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值