ClipImageClipImageClipImageClipImageClipImageClipImage
using System; using System.Drawing; using System.Windows.Forms; namespace ClipImage { public partial class FormImage : Form { #region 自定义对象 private Point position; private Rectangle clip; private NotifyIcon notifyInfo; #endregion public FormImage() { #region InitializeComponent(); this.TopMost = true; // 前端显示。 this.ShowInTaskbar = false; // 在 Windows 任务栏中隐藏窗体。 this.DoubleBuffered = true; // 双缓冲绘制图形。 this.Cursor = Cursors.Cross; // 获取十字线光标。 this.FormBorderStyle = FormBorderStyle.None; // 窗体无边框。 this.Bounds = Screen.GetBounds(this); // 获取屏幕的边界。 this.TransparencyKey = this.BackColor; // 窗体背景透明化。 notifyInfo = new NotifyIcon(); notifyInfo.Visible = true; // 图标在任务栏的通知区域中可见。 notifyInfo.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); // 启动程序图标。 notifyInfo.Text = AppDomain.CurrentDomain.FriendlyName; // 启动程序名称。 notifyInfo.BalloonTipClosed += new EventHandler(notifyInfo_BalloonTipClosed); // 在用户关闭气球提示时发生。 notifyInfo.MouseClick += new MouseEventHandler(notifyInfo_MouseClick); #endregion } #region OnMouseDown protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); switch (e.Button) { case MouseButtons.Left: position = e.Location; // 设置起始位置。 break; case MouseButtons.Right: if (clip.Width > 1 && clip.Height > 1) { clip.Offset(1, 1); // 平移。 using (Bitmap bmp = new Bitmap(--clip.Width, --clip.Height)) using (Graphics g = Graphics.FromImage(bmp)) { g.CopyFromScreen(clip.Location, Point.Empty, clip.Size); // 截图。 bmp.Save("Image.png", bmp.RawFormat); // 保存图片。 Clipboard.SetImage(bmp); // 图片存储到剪贴板中。 } System.Diagnostics.Process.Start("mspaint.exe", "Image.png"); // 用画图打开图片。 } clip = Rectangle.Empty; this.BackgroundImage.Dispose(); this.BackgroundImage = null; break; } } #endregion #region OnMouseMove protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { clip.X = Math.Min(position.X, e.X); clip.Y = Math.Min(position.Y, e.Y); clip.Width = Math.Abs(position.X - e.X); clip.Height = Math.Abs(position.Y - e.Y); this.Refresh(); // 立即重绘图形。 } } #endregion #region OnPaint protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawRectangle(Pens.Red, clip); e.Dispose(); } #endregion #region NotifyIcon private void notifyInfo_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: this.BackgroundImage = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(this.BackgroundImage)) { g.CopyFromScreen(Point.Empty, Point.Empty, this.Size); } this.Activate(); // 激活窗体并给予它焦点。 break; case MouseButtons.Right: notifyInfo.ShowBalloonTip(10, notifyInfo.Text, " 在单击图标时截图", ToolTipIcon.Info); break; } } private void notifyInfo_BalloonTipClosed(object sender, EventArgs e) { notifyInfo.Dispose(); Application.Exit(); } #endregion } }using System; using System.Drawing; using System.Windows.Forms; namespace ClipImage { public partial class FormImage : Form { #region 自定义对象 private Point position; private Rectangle clip; private NotifyIcon notifyInfo; #endregion public FormImage() { #region InitializeComponent(); this.TopMost = true; // 前端显示。 this.ShowInTaskbar = false; // 在 Windows 任务栏中隐藏窗体。 this.DoubleBuffered = true; // 双缓冲绘制图形。 this.Cursor = Cursors.Cross; // 获取十字线光标。 this.FormBorderStyle = FormBorderStyle.None; // 窗体无边框。 this.Bounds = Screen.GetBounds(this); // 获取屏幕的边界。 this.TransparencyKey = this.BackColor; // 窗体背景透明化。 notifyInfo = new NotifyIcon(); notifyInfo.Visible = true; // 图标在任务栏的通知区域中可见。 notifyInfo.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); // 启动程序图标。 notifyInfo.Text = AppDomain.CurrentDomain.FriendlyName; // 启动程序名称。 notifyInfo.BalloonTipClosed += new EventHandler(notifyInfo_BalloonTipClosed); // 在用户关闭气球提示时发生。 notifyInfo.MouseClick += new MouseEventHandler(notifyInfo_MouseClick); #endregion } #region OnMouseDown protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); switch (e.Button) { case MouseButtons.Left: position = e.Location; // 设置起始位置。 break; case MouseButtons.Right: if (clip.Width > 1 && clip.Height > 1) { clip.Offset(1, 1); // 平移。 using (Bitmap bmp = new Bitmap(--clip.Width, --clip.Height)) using (Graphics g = Graphics.FromImage(bmp)) { g.CopyFromScreen(clip.Location, Point.Empty, clip.Size); // 截图。 bmp.Save("Image.png", bmp.RawFormat); // 保存图片。 Clipboard.SetImage(bmp); // 图片存储到剪贴板中。 } System.Diagnostics.Process.Start("mspaint.exe", "Image.png"); // 用画图打开图片。 } clip = Rectangle.Empty; this.BackgroundImage.Dispose(); this.BackgroundImage = null; break; } } #endregion #region OnMouseMove protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { clip.X = Math.Min(position.X, e.X); clip.Y = Math.Min(position.Y, e.Y); clip.Width = Math.Abs(position.X - e.X); clip.Height = Math.Abs(position.Y - e.Y); this.Refresh(); // 立即重绘图形。 } } #endregion #region OnPaint protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawRectangle(Pens.Red, clip); e.Dispose(); } #endregion #region NotifyIcon private void notifyInfo_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: this.BackgroundImage = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(this.BackgroundImage)) { g.CopyFromScreen(Point.Empty, Point.Empty, this.Size); } this.Activate(); // 激活窗体并给予它焦点。 break; case MouseButtons.Right: notifyInfo.ShowBalloonTip(10, notifyInfo.Text, " 在单击图标时截图", ToolTipIcon.Info); break; } } private void notifyInfo_BalloonTipClosed(object sender, EventArgs e) { notifyInfo.Dispose(); Application.Exit(); } #endregion } }
- 1
- phoenixbrave2012-09-03挺好 对我的帮助很多
- 粉丝: 21
- 资源: 295
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现图像处理,本程序使用背景差分法对来往车辆进行检测和跟踪.rar
- 基于matlab实现视频监控中车型识别代码,自己写的,希望和大家多多交流.rar
- sdk.config
- 基于matlab实现配电网三相潮流计算方法,对几种常用的配电网潮流计算方法进行了对比分析.rar
- 基于matlab实现配电网潮流 经典33节点 前推回代法潮流计算 回代电流 前推电压 带注释.rar
- 基于matlab实现模拟退火遗传算法的车辆调度问题研究,用MATLAB语言加以实现.rar
- 基于matlab实现蒙特卡洛的的移动传感器节点定位算法仿真代码.rar
- 华中数控系统818用户说明书
- 基于matlab实现卡尔曼滤波器完成多传感器数据融合 对多个机器人的不同传感器数据进行融合估计足球精确位置.rar
- 基于matlab实现进行简单车辆识别-车辆检测.rar