Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class ArgomentiEvento
- Private _posizione As Point
- Private _pulsante As Byte
- Public Property Posizione As Point
- Get
- Return _posizione
- End Get
- Set(value As Point)
- _posizione = value
- End Set
- End Property
- Public Property Pulsante As Byte
- Get
- Return _pulsante
- End Get
- Set(value As Byte)
- _pulsante = value
- End Set
- End Property
- Public Sub New(pos As Point, puls As Byte)
- Posizione = pos
- Pulsante = puls
- End Sub
- End Class
- Public Class Form1
- Private Delegate Sub delegato(oggetto As Object, argomenti As argomentiEvento)
- Private Event MuoviMouse As delegato
- Private stringa As String
- Private dbBuffer As BufferedGraphics
- Private dbBufferContext As New BufferedGraphicsContext
- Private Const WM_MOUSEMOVE As Long = &H200
- Protected Overrides Sub WndProc(ByRef m As Message)
- MyBase.WndProc(m)
- Select Case m.Msg
- Case WM_MOUSEMOVE
- Dim x As Integer
- Dim y As Integer
- x = m.LParam.ToInt32 And &HFFFF
- y = m.LParam.ToInt32 >> 16
- RaiseEvent MuoviMouse(Me, New ArgomentiEvento(New Point(x, y), m.WParam.ToInt32))
- End Select
- End Sub
- Private Sub Form_MuoviMouse(sender As Object, e As argomentiEvento) Handles Me.muoviMouse
- Dim pulsante As String = ""
- Select Case e.Pulsante
- Case 0
- pulsante = "NESSUNO"
- Case 1
- pulsante = "SINISTRO"
- Case 2
- pulsante = "DESTRO"
- End Select
- stringa = "X = " & e.Posizione.X & " Y = " & e.Posizione.Y & " pulsante premuto = " & pulsante
- Dim dimensione As SizeF = Me.CreateGraphics.MeasureString(stringa, New Font("Arial", 20, FontStyle.Bold))
- Dim x As Integer = (Me.Width - dimensione.Width) / 2
- Dim y As Integer = (Me.Height - dimensione.Height) / 2
- dbBuffer.Graphics.Clear(Me.BackColor)
- dbBuffer.Graphics.DrawString(stringa, New Font("Arial", 20, FontStyle.Regular), New SolidBrush(Color.Black), New Point(x, y))
- dbBuffer.Render(Me.CreateGraphics)
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
- dbBufferContext.MaximumBuffer = Me.Size
- dbBuffer = dbBufferContext.Allocate(Me.CreateGraphics, New Rectangle(New Point(0, 0), Me.Size))
- dbBuffer.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement