实例介绍
【实例简介】
【实例截图】
【核心代码】
/*********************************************
*
* 用于捕获制定区域的窗口
* 它表现为带有8个小方块的矩形
* 8个小方块
* 0--1--2
* 3 4
* 5--6--7
* 一个拖动该变位置和大小
* 将根据其区域内的图像来确定捕获的最终图像
* -----------------------------------------
* by zhouyinhui 2006_6_26
*********************************************/
/*
* 未解决的问题:
*
* 拖动小方块以改变大小
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace QQCatchScreen
{
public partial class FormCatcher : Form
{
public FormCatcher()
{
InitializeComponent();
}
public bool isMouseLeftDown = false;
/// <summary>
/// 鼠标按下时鼠标与窗体位置横坐标差
/// </summary>
public int dxCursorToWindow = 0;
/// <summary>
/// 鼠标按下时鼠标与窗体位置横坐标差
/// </summary>
public int dyCursorToWindow = 0;
private void FormCatcher_Load(object sender, EventArgs e)
{
this.Resize = new EventHandler(FormCatcher_Resize);
}
void FormCatcher_Resize(object sender, EventArgs e)
{
this.Refresh();
}
//绘制矩形边框与8个小方块
private void FormCatcher_Paint(object sender, PaintEventArgs e)
{
using (Graphics g = e.Graphics)
{
Rectangle rect = new Rectangle(1, 1, this.ClientRectangle.Width - 3, this.ClientRectangle.Height - 3);
g.DrawRectangle(Pens.Red, rect);
//绘制小方块
for (int i = 0; i <= 7; i )
{
g.FillRectangle(Brushes.Red, this.GetBoundsOfSmallBlock(i));
}
}
}
/// <summary>
/// 获取指定序号的小方块的位置
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
private Rectangle GetBoundsOfSmallBlock(int index)
{
int x =0;
int y=0;
int w=4;
int h=4;
switch (index)
{
case 0:
case 3:
case 5:
x = 0;
break;
case 1:
case 6:
x = this.ClientRectangle.Width / 2-3;
break;
case 2:
case 4:
case 7:
x = this.ClientRectangle.Width - 4;
break;
default:
throw new IndexOutOfRangeException("小方块序号错误,应该在[0,7]");
}
switch (index)
{
case 0:
case 1:
case 2:
y = 0;
break;
case 3:
case 4:
y = this.ClientRectangle.Height / 2-3;
break;
case 5:
case 6:
case 7:
y = this.ClientRectangle.Height - 4;
break;
default:
throw new IndexOutOfRangeException("小方块序号错误,应该在[0,7]");
}
return new Rectangle(x, y, w, h);
}
private void FormCatcher_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.isMouseLeftDown = true;
this.dxCursorToWindow = Cursor.Position.X - this.Location.X;
this.dyCursorToWindow = Cursor.Position.Y - this.Location.Y;
}
}
private void FormCatcher_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.isMouseLeftDown = false;
this.dxCursorToWindow = this.dyCursorToWindow = 0;
}
}
private void FormCatcher_MouseLeave(object sender, EventArgs e)
{
this.isMouseLeftDown = false;
this.dxCursorToWindow = this.dyCursorToWindow = 0;
}
private void FormCatcher_MouseMove(object sender, MouseEventArgs e)
{
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论