模仿QQ截图片

王朝学院·作者佚名  2016-05-16
窄屏简体版  字體: 小  |  中  |  大  |  超大  

模仿QQ截图片两个picturebox,一个放图片完整代码如下using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.OleDb;using System.xml;namespace Test{ public partial class Form1 : Form { PRivate bool MouseIsDown = false; private int _x, _y; private Rectangle MouseRect = Rectangle.Empty; public Form1() { InitializeComponent(); } private void ResizeToRectangle(Point p) { DrawRectangle(); MouseRect.Width = p.X - MouseRect.Left; MouseRect.Height = p.Y - MouseRect.Top; DrawRectangle(); } private void DrawRectangle() { Rectangle rect = this.RectangleToScreen(MouseRect); ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed); } private void DrawStart(Point StartPoint) { barkPictureBox.Capture = true; Cursor.Clip = this.RectangleToScreen(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height)); MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0); } private void button1_Click(object sender, EventArgs e) { } void barkPictureBox_MouseUp(object sender, MouseEventArgs e) { barkPictureBox.Capture = false; Cursor.Clip = Rectangle.Empty; MouseIsDown = false; DrawRectangle(); if (MouseRect.X == 0 || MouseRect.Y == 0 || MouseRect.Width == 0 || MouseRect.Height == 0) //如果区域有一个是0就返回 { } else { ///代码 } MouseRect = Rectangle.Empty; int sx = _x < e.X ? _x : e.X; int sy = _y < e.Y ? _y : e.Y; int w = Math.Abs(_x - e.X); int h = Math.Abs(_y - e.Y); Graphics g = Graphics.FromHwnd(pictureBox2.Handle); g.Clear(pictureBox2.BackColor); g.DrawImage(barkPictureBox.Image, new Rectangle(0, 0, w, h), sx, sy, w, h, GraphicsUnit.Pixel); } void barkPictureBox_MouseMove(object sender, MouseEventArgs e) { if (MouseIsDown) ResizeToRectangle(new Point(e.X + barkPictureBox.Location.X, e.Y + barkPictureBox.Location.Y)); } void barkPictureBox_MouseDown(object sender, MouseEventArgs e) { _x = e.X; _y = e.Y; MouseIsDown = true; DrawStart(new Point(e.X + barkPictureBox.Location.X, e.Y + barkPictureBox.Location.Y)); } private void Form1_Load(object sender, EventArgs e) { barkPictureBox.MouseDown += new MouseEventHandler(barkPictureBox_MouseDown); barkPictureBox.MouseMove += new MouseEventHandler(barkPictureBox_MouseMove); barkPictureBox.MouseUp += new MouseEventHandler(barkPictureBox_MouseUp); } }}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航