Imports System.Drawing.Drawing2D
Public Class Form2
Inherits System.Windows.Forms.Form
Private IsDraging As Boolean = False 'Varible for draging from
Private lCurX, lCurY As Long 'needed for current x, y values
Private WithEvents tTimer As Timer = New Timer() 'setup timer (no need for a formcontrol)
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
Me.ClientSize = New System.Drawing.Size(272, 150)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form2"
Me.Text = "Form2"
End Sub
#End Region
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'avvio in un altro thread la costruzione della grafica
'Dim t2 As System.Threading.Thread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf drawScocca))
't2.Start()
drawScocca()
End Sub
Private Sub drawScocca()
Dim Path As New GraphicsPath()
Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")
Dim x, y, i As Long
Dim rect As Rectangle
Dim colorFirst As Color = b.GetPixel(1, 1)
For x = 0 To b.Width - 1
For y = 0 To b.Height - 1
If b.GetPixel(x, y).Equals(colorFirst) Then
'non lo disegno perch?devo fare la trasparenza
Else
rect = New Rectangle(x, y, 1, 1)
Path.AddRectangle(rect)
End If
Next y
Next x
Me.Region = New Region(Path)
End Sub
Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")
g.DrawImage(b, 0, 0, b.Width, b.Height)
g.Dispose()
End Sub
Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
lCurX = e.X : lCurY = e.Y 'Set the Current x and y values
IsDraging = True 'Begin Draging Form
tTimer.Enabled = True 'Enable Drag Timer
End Sub
Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
'Checks the state of the mouseevent and moves form Accordingly
If IsDraging = True Then
'Move the form accordingly to cursor x, y positions (minus) the current form x, y positions
Dim curxx As Integer = Cursor.Position.X
Dim curyy As Integer = Cursor.Position.Y
Me.SetDesktopLocation(curxx - lCurX, curyy - lCurY)
End If
'tTimer.Enabled = False 'Cancel timer, no longer needed
End Sub
Private Sub Form2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
IsDraging = False 'No Longer Moving Form
tTimer.Enabled = False 'Cancel Timer
End Sub
End Class