/// <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;
评论加载中…
![]() |