Public Class Form1
Public r As Rectangle
Public sp As Integer = 10
Public w As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawRectangle(New Pen(Color.Red, sp), r)
e.Graphics.Dispose()
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
r.X = e.X
r.Y = e.Y
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.X < r.X Then
r.Width = r.X - e.X
r.X = e.X
Else
r.Width = e.X - r.X
End If
If e.Y < r.Y Then
r.Height = r.Y - e.Y
r.Y = e.Y
Else
r.Height = e.Y - r.Y
End If
Me.Invalidate(r)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
w = 1
r.Height = 0
r.Width = 0
Me.Refresh()
End Sub
End Class
questo è il codice