Public
Class
Form1
Dim
mDn, mMv, mUp, kLc
As
Point
Dim
vR
As
Rectangle
Dim
Tah, Kriz
As
Boolean
Dim
Fnt
As
Font =
New
Font(
"Verdana"
, 18, FontStyle.Bold)
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
, _
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
PictureBox1.Dock = DockStyle.Fill
PictureBox1.BackColor = Color.Ivory
End
Sub
Private
Sub
PictureBox1_MouseDown(
ByVal
sender
As
Object
, _
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
PictureBox1.MouseDown
mMv.X = 0 : mMv.Y = 0
vR =
New
Rectangle(0, 0, 0, 0)
Kriz =
False
Tah =
False
mDn = e.Location
PictureBox1.Invalidate()
End
Sub
Private
Sub
PictureBox1_MouseMove(
ByVal
sender
As
Object
, _
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
PictureBox1.MouseMove
If
e.Button = Windows.Forms.MouseButtons.Left
Then
Dim
w
As
Integer
=
Me
.Left +
Me
.Width - 5
Dim
h
As
Integer
=
Me
.Top +
Me
.Height - 5
If
e.X < 0
Then
Cursor.Position =
New
Point(
Me
.Left + 5, Cursor.Position.Y)
End
If
If
e.Y < 0
Then
Cursor.Position =
New
Point(Cursor.Position.X,
Me
.Top + 30)
End
If
If
Cursor.Position.X >= w
Then
Cursor.Position =
New
Point(w, Cursor.Position.Y)
End
If
If
Cursor.Position.Y > h
Then
Cursor.Position =
New
Point(Cursor.Position.X, h)
End
If
mMv = e.Location
Tah =
True
PictureBox1.Invalidate()
End
If
End
Sub
Private
Sub
PictureBox1_MouseUp(
ByVal
sender
As
Object
, _
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
PictureBox1.MouseUp
mMv = e.Location
mUp = e.Location
kLc.X = mDn.X + (mMv.X - mDn.X) / 2 - 13
kLc.Y = mDn.Y + (mMv.Y - mDn.Y) / 2 - 14
Kriz =
True
Tah =
False
mDn.X = 0 : mDn.Y = 0
mMv.X = 0 : mMv.Y = 0
PictureBox1.Invalidate()
End
Sub
Private
Sub
PictureBox1_Paint(
ByVal
sender
As
Object
, _
ByVal
e
As
System.Windows.Forms.PaintEventArgs)
Handles
PictureBox1.Paint
Dim
mDn2
As
Point
Dim
mRw, mRh
As
Integer
mRw = Math.Abs(mMv.X - mDn.X)
mRh = Math.Abs(mMv.Y - mDn.Y)
If
(mMv.X - mDn.X) < 0
Then
mDn2.X = mMv.X
Else
mDn2.X = mDn.X
End
If
If
(mMv.Y - mDn.Y) < 0
Then
mDn2.Y = mMv.Y
Else
mDn2.Y = mDn.Y
End
If
If
Tah
Then
e.Graphics.FillRectangle(
New
SolidBrush(Color.FromArgb(16, Color.Blue)), mDn2.X, mDn2.Y, mRw, mRh)
e.Graphics.DrawRectangle(
New
Pen(Color.DarkGray, 1), mDn2.X, mDn2.Y, mRw, mRh)
vR =
New
Rectangle(mDn2.X, mDn2.Y, mRw, mRh)
End
If
If
Kriz
Then
e.Graphics.DrawString(
"X"
, Fnt, Brushes.DarkBlue, kLc.X, kLc.Y)
e.Graphics.DrawRectangle(
New
Pen(Color.Red, 1), vR)
End
If
End
Sub
End
Class