1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
'Rappel MSDN Doc:
'L'interface utilisateur -doit- défiler lorsque le delta cumulé correspond à plus ou moins 120
'de la valeur delta.
'L'interface utilisateur -doit- faire défiler le nombre de lignes logiques
'retourné par la propriété SystemInformation "MouseWheelScrollLines"
'Le taux de défilement doit demeurer constant,
'c'est-à-dire un défilement de SystemInformation.MouseWheelScrollLines lignes par 120 unités delta de déplacement de roulette.
'fin de citation.
'Cela signifie que :
'-que le standard pour une souris est de generer un Delta +/- 120 à chaque event MouseWheel
'-que le scrolling "manage" par toi doit respecter la formule :
' NbLignesADefiler = Delta*TauxConstant( SystemInformation.MouseWheelScrollLines / 120)
'Comme ta souris genere des multiples de 120 il faut un test sur e.delta avant de
'Scroller.
Imports System.Drawing.Drawing2D
Public Class frmMouseEvent
Private mousePath As GraphicsPath = New GraphicsPath
Private myFont As Font = New Font("Arial", 12)
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
lblMouseButtons.Font = myFont
lblDelta.Font = myFont
lblNbLigneTxtToMove.Font = myFont
lblNbPixelToMove.Font = myFont
lblMouseButtons.Font = myFont
lblScrollLines.Font = myFont
'Informations supplémentaires sur la souris sont également affichées à l'écran, à partir de la classe SystemInformation
lblMouseButtons.Text = "SystemInformation.MouseButtons: " + vbCrLf + SystemInformation.MouseButtons.ToString()
lblScrollLines.Text = "SystemInformation.MouseWheelScrollLines: " + vbCrLf + SystemInformation.MouseWheelScrollLines.ToString()
'inspecte cette ligne pour ce qui de ta souris pour
'voir si elle est true
lblNativeSupport.Text = "SystemInformation.NativeMouseWheelSupport: " + SystemInformation.NativeMouseWheelSupport.ToString
lblNativeSupport.Font = myFont
End Sub
Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
' Update the mouse path with the mouse information
Dim mouseDownLocation As New Point(e.X, e.Y)
Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Left
eventString = "LEFT"
Case MouseButtons.Right
eventString = "RIGHT"
Case MouseButtons.Middle
eventString = "MIDDLE"
Case MouseButtons.XButton1
eventString = "X1"
Case MouseButtons.XButton2
eventString = "X2"
Case MouseButtons.None
eventString = Nothing
End Select
If (eventString IsNot Nothing) Then
mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), Me.Panel1.Font.Size, mouseDownLocation, StringFormat.GenericDefault)
Dim rect As Rectangle = New Rectangle(mouseDownLocation, New Size(100, 100))
mousePath.AddEllipse(rect)
End If
Panel1.Focus()
Panel1.Invalidate()
End Sub
Private Sub Panel1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseWheel
' Update the drawing based upon the mouse wheel scrolling.
'si tu as un delta non-conforme avec ta souris ,pour te conformer au standard msdn
'tu dois defiler si delta >120 ou <-120
'ceci donne:
If e.Delta = 120 Or e.Delta = -120 Then 'scroll
Dim numberOfTextLinesToMove As Integer = CInt(e.Delta * SystemInformation.MouseWheelScrollLines / 120)
Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * Me.Panel1.Font.Size
If numberOfPixelsToMove <> 0 Then
Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
translateMatrix.Translate(0, numberOfPixelsToMove)
mousePath.Transform(translateMatrix)
End If
lblDelta.Text = "Delta :" & e.Delta.ToString
lblNbLigneTxtToMove.Text = "Lignes :" & numberOfTextLinesToMove
lblNbPixelToMove.Text = "Pixels :" & numberOfPixelsToMove.ToString
Panel1.Invalidate()
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
Panel1.Invalidate()
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
' Perform the painting of the Panel.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub
End Class |
Partager