2007-01-05

C#模仿QQ截图功能

来源: CSDN 作者:往事随风 评论 0 条
 
}
}

/// <summary>
/// 设置鼠标方案
/// </summary>
private void SetCursor()
{
Cursor cr = Cursors.Default;

if(index == 1 || index == 5)
{
cr = Cursors.SizeNWSE;
}
else if(index == 2 || index == 6)
{
cr = Cursors.SizeNS;
}
else if(index == 3 || index == 7)
{
cr = Cursors.SizeNESW;
}
else if(index == 4 || index == 8)
{
cr = Cursors.SizeWE;
}
else if(index == 0)
{
cr = Cursors.SizeAll;
}
Cursor.Current = cr;
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawRectangle(new Pen(this.ForeColor),this.area);

for(int i = 1;i < 9;i )
{
e.Graphics.FillRectangle(new SolidBrush(Color.Green),this.GetHandleRect(i));
}
}

private Rectangle GetHandleRect(int index)
{
Point point = GetHandle(index);
return new Rectangle(point.X - 3, point.Y - 3, 6, 6);
}

private Point GetHandle(int index)
{
int x, y, xCenter, yCenter;

xCenter = area.X area.Width/2;
yCenter = area.Y area.Height/2;
x = area.X;
y = area.Y;

switch ( index )
{
case 1:
x = area.X;
y = area.Y;
break;
case 2:
x = xCenter;
y = area.Y;
break;
case 3:
x = area.Right;
y = area.Y;
break;
case 4:
x = area.Right;
y = yCenter;
break;
case 5:
x = area.Right;
y = area.Bottom;
break;
case 6:
x = xCenter;
y = area.Bottom;
break;
case 7:
x = area.X;
y = area.Bottom;
break;
case 8:
x = area.X;
y = yCenter;
break;
}

return new Point(x, y);
}

protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp (e);
int left = area.Left;
int top = area.Top;
int right = area.Right;
int bottom = area.Bottom;
area.X = Math.Min(left,right);
area.Y = Math.Min(top,bottom);
area.Width = Math.Abs(left-right);
area.Height = Math.Abs(top-bottom);
this.tiptext.Text = selectedString;
if(e.Button == MouseButtons.Right)
{
if(this.area == Rectangle.Empty)
{
this.Close();
}
else
{
this.area=Rectangle.Empty;
this.Invalidate();
}
}
this.index = this.GetSelectedHandle(new Point(e.X,e.Y));
this.SetCursor();
}

private int GetSelectedHandle(Point p)
{
int index = -1;
共8页: 上一页 [1] [2] [3] [4] [5] 6 [7] [8] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:Java应用web开发备用工具  
下一篇:详细讲述Java中的克隆
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号