private void
Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Graphics g=CreateGraphics();
inborder
= borderRegion.IsVisible(new Point(e.X,e.Y),g);
g.Dispose();
if(!moving
& !sizing & !inborder)
{
if(closerPos==45)
{
opening=false;
this.closer.Interval=2000;
this.closer.Enabled=true;
}
inborder=false;
Cursor=Cursors.Arrow;
//Do
non-border processing here...
return;
}
if(!sizing)
{
if((e.Y<45
& e.X<45))
{
this.Cursor=Cursors.SizeNWSE;
sizeAction=SizeAction.SizeTopLeft;
}
else
if(e.Y>this.Height-45
& e.X>this.Width-45)
{
this.Cursor=Cursors.SizeNWSE;
sizeAction=SizeAction.SizeBottomRight;
}
else
if (e.Y<45 & e.X>this.Width-45)
{
if(closerPos!=45)
{
opening=true;
this.timer1.Interval=10;
this.timer1.Enabled=true;
}
this.Cursor=Cursors.SizeNESW;
sizeAction=SizeAction.SizeTopRight;
}
else
if(e.Y>this.Height-45
& e.X<45)
{
this.Cursor=Cursors.SizeNESW;
sizeAction=SizeAction.SizeBottomLeft;
}
else
if(e.X<45)
{
this.Cursor=Cursors.SizeWE;
sizeAction=SizeAction.SizeLeft;
}
else
if(e.X>this.Width-45)
{
this.Cursor=Cursors.SizeWE;
sizeAction=SizeAction.SizeRight;
}
else
if(e.Y>this.Height-45)
{
this.Cursor=Cursors.SizeNS;
sizeAction=SizeAction.SizeBottom;
}
else
if (e.Y<45)
{
this.Cursor=Cursors.SizeNS;
sizeAction=SizeAction.SizeTop;
}
}
if
(sizing)
{
Point
t,s,oldLoc;
switch(sizeAction)
{
case
SizeAction.SizeTop:
this.Location=new
Point(this.Location.X,this.Location.Y+e.Y);
this.Size=new
Size(this.Size.Width,this.Size.Height-e.Y);
break;
case
SizeAction.SizeLeft:
this.Location=new
Point(this.Location.X+e.X,this.Location.Y);
this.Size=new
Size(this.Size.Width-e.X ,this.Size.Height);
break;
case
SizeAction.SizeRight:
this.Size=new
Size(e.X,this.Size.Height);
break;
case
SizeAction.SizeBottom:
this.Size=new
Size(this.Size.Width,e.Y);
break;
case
SizeAction.SizeTopLeft:
t=new
Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);
Location=this.PointToScreen(t);
this.Size=new
Size(this.Size.Width-t.X ,this.Size.Height-t.Y);
break;
case
SizeAction.SizeBottomLeft:
oldLoc=Location;
t=new
Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);
s=this.PointToScreen(t);
this.Location=new
Point(s.X,Location.Y);
this.Size=new
Size(this.Size.Width-(Location.X-oldLoc.X) ,e.Y+(this.Height-cursorOffset.Y)
);
this.cursorOffset.Y=e.Y;
break;
case
SizeAction.SizeTopRight:
oldLoc=Location;
t=new
Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);
s=this.PointToScreen(t);
this.Location=new
Point(Location.X,s.Y);
this.Size=new
Size(e.X+(this.Size.Width-cursorOffset.X),this.Size.Height-(Location.Y-oldLoc.Y));
this.cursorOffset=new
Point(e.X,cursorOffset.Y);
break;
case
SizeAction.SizeBottomRight:
this.Size=new
Size(e.X+(this.Size.Width-cursorOffset.X),e.Y+(this.Size.Height-this.cursorOffset.Y));
cursorOffset=new
Point(e.X,e.Y);
break;
}
}
if
(moving)
{
this.Cursor=Cursors.SizeAll;
this.Location=PointToScreen(new
Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y));
}
}
Private Sub
Form1_MouseMove(ByVal sender
As Object,
ByVal e As
System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseMove
Dim
g As Graphics = CreateGraphics()
inborder
= borderRegion.IsVisible(New Point(e.X, e.Y), g)
g.Dispose()
If
Not moving And
Not sizing And
Not inborder Then
If
closerPos = 45 Then
opening = False
Me.closer.Interval
= 2000
Me.closer.Enabled
= True
End
If
inborder = False
Cursor = Cursors.Arrow
'Do
non-border processing here...
Return
End
If
If
Not sizing Then
If
e.Y < 45 And e.X < 45
Then
Me.Cursor
= Cursors.SizeNWSE
sizeAction = sizeAction.SizeTopLeft
ElseIf
e.Y > Me.Height - 45
And e.X > Me.Width - 45
Then
Me.Cursor
= Cursors.SizeNWSE
sizeAction = sizeAction.SizeBottomRight
ElseIf
e.Y < 45 And e.X > Me.Width
- 45 Then
If
closerPos <> 45 Then
opening = True
Me.timer1.Interval
= 10
Me.timer1.Enabled
= True
End
If
Me.Cursor
= Cursors.SizeNESW
sizeAction
= sizeAction.SizeTopRight
ElseIf
e.Y > Me.Height - 45
And e.X < 45 Then
Me.Cursor
= Cursors.SizeNESW
sizeAction
= sizeAction.SizeBottomLeft
ElseIf
e.X < 45 Then
Me.Cursor
= Cursors.SizeWE
sizeAction
= sizeAction.SizeLeft
ElseIf
e.X > Me.Width - 45
Then
Me.Cursor
= Cursors.SizeWE
sizeAction = sizeAction.SizeRight
ElseIf
e.Y > Me.Height - 45
Then
Me.Cursor
= Cursors.SizeNS
sizeAction = sizeAction.SizeBottom
ElseIf
e.Y < 45 Then
Me.Cursor
= Cursors.SizeNS
sizeAction = sizeAction.SizeTop
End
If
End
If
If
sizing Then
Dim
t, s, oldLoc As Point
Select
Case sizeAction
Case
sizeAction.SizeTop
Me.Location
= New Point(Me.Location.X,
Me.Location.Y + e.Y)
Me.Size
= New Size(Me.Size.Width,
Me.Size.Height - e.Y)
Case
sizeAction.SizeLeft
Me.Location
= New Point(Me.Location.X
+ e.X, Me.Location.Y)
Me.Size
= New Size(Me.Size.Width
- e.X, Me.Size.Height)
Case
sizeAction.SizeRight
Me.Size
= New Size(e.X, Me.Size.Height)
Case
sizeAction.SizeBottom
Me.Size
= New Size(Me.Size.Width,
e.Y)
Case
sizeAction.SizeTopLeft
t
= New Point(e.X - cursorOffset.X, e.Y -
cursorOffset.Y)
Location = Me.PointToScreen(t)
Me.Size
= New Size(Me.Size.Width
- t.X, Me.Size.Height - t.Y)
Case
sizeAction.SizeBottomLeft
oldLoc = Location
t
= New Point(e.X - cursorOffset.X, e.Y -
cursorOffset.Y)
s
= Me.PointToScreen(t)
Me.Location
= New Point(s.X, Location.Y)
Me.Size
= New Size(Me.Size.Width
- (Location.X - oldLoc.X), e.Y + (Me.Height -
cursorOffset.Y))
Me.cursorOffset.Y
= e.Y
Case
sizeAction.SizeTopRight
oldLoc = Location
t
= New Point(e.X - cursorOffset.X, e.Y -
cursorOffset.Y)
s
= Me.PointToScreen(t)
Me.Location
= New Point(Location.X, s.Y)
Me.Size
= New Size(e.X + (Me.Size.Width
- cursorOffset.X), Me.Size.Height - (Location.Y
- oldLoc.Y))
Me.cursorOffset
= New Point(e.X, cursorOffset.Y)
Case
sizeAction.SizeBottomRight
Me.Size
= New Size(e.X + (Me.Size.Width
- cursorOffset.X), e.Y + (Me.Size.Height -
Me.cursorOffset.Y))
cursorOffset
= New Point(e.X, e.Y)
End
Select
End
If
If
moving Then
Me.Cursor
= Cursors.SizeAll
Me.Location
= PointToScreen(New Point(e.X - cursorOffset.X,
e.Y - cursorOffset.Y))
End
If
End
Sub 'Form1_MouseMove