none
dynamic mouse move left/right button press. RRS feed

  • Question

  • I'm stupid, and often programmers try to do too much within one event handler, in this case Mouse_Move. In the Mouse_Move  event handler, it is easy to identify a left or right mouse press, however; the press is handled as a single press event that terminates somewhere else in the event handlers. What I would like to have conceptually is the left and right mouse buttons act as throttles to zoom in or out on a form. In other words, holding the left mouse button down continues to Zoom in, holding the right button down continues to zoom out. When neither a right or left press is in effect, the operator is free to adjust the point of interest by simply moving the cursor. (Code not shown.) As it is now, it requires clicking multiple (massive number of times), or, moving the mouse cursor slightly to trigger another event. By code, I pop the Cursor back to the point where the operator first issued a mouse press. (Although that works, it is confusing to the operator to remember to scoot the mouse a little.) It would be better to return to the Mouse_Move event as long as the mouse button is down. Does any one know the sequence of event handlers that a mouse interrupt generates so that I can place a call back to the Mouse_Move event at the end of the chain? Better ideas welcome also! 

       Case Is = 1048576 ' ZOOMING, LEFT CLICK (only fire once. would like it to continue firing as long as mouse button pressed.)
                        ScreenX = Xcursor
                        ScreenY = Ycursor
                        Zoomval = Zoomval + 0.2 * Zoomval 'increase zoom some, then redraw the screen.
                        If Zoomval > 500 Then Zoomval = 500
                        PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                        PrevYmouse = Me.Height / 2
                        MouseReEntryF = 0 'WAS 1 'tried class flag values in most of the of the other event handlers. 
                        DrawCursorOnlyF = 0
                        RedrawScreen() 'routine to redraw the screen using GDI+ (inverted transform)

    Case Is = 2097152

                        ScreenX = Xcursor
                        ScreenY = Ycursor
                        Zoomval = Zoomval - 0.2 * Zoomval
                        If Zoomval <= 0.1 Then Zoomval = 0.1
                        PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                        PrevYmouse = Me.Height / 2
                        MouseReEntryF = 0 'WAS 1
                        DrawCursorOnlyF = 0
                        RedrawScreen() 'routine to redraw the screen using GDI+
       End Select


    • Edited by fmpeck Wednesday, January 17, 2018 4:08 PM
    Wednesday, January 17, 2018 4:03 PM

Answers

  • REED,

    Thank you for all your efforts. Below is some VB code using Mouse_Move and Mouse_Down. When operator clicks Mouse_Down, the initial screen is drawn. (That code is shown after Mouse_Move code shown below.) e.Delta does not work if the mouse driver does not submit a signed integer. It is always positive. Programmers have a different expectation than operators, and my interpretation of what e.Delta should be doing may have been the problem, but if you read MSDS descriptions, I still think I'm right. This may explain all of the bugs reported on the internet about mouse functions not working. Below is my work-around that uses the Center of the Screen and e.Y to interpret what the operator is requesting.  

     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

            'e.Delta DOES NOT SUBMIT NEGATIVE NUMBERS!!! IT IS NOT RELATIVE. THEREFORE USE CENTER SCREEN POSITION TO INTERPRET OPERATOR'S MOVEMENT

            'PLACING THE ZOOMING CODE AHEAD OF CURSOR MOVEMENT CODE PREVENTS THE CENTER SCREEN OBJECT POSITION OF INTEREST FROM CHANGING BY USE OF EXIT SUB

            'LET UP ON MOUSE AND MOVE CURSOR TO 'ADJUST' POSITION OF INTEREST, HOLD LEFT MOUSE DOWN, AND ZOOM FURTHER AS DESIRED. USE MOUSE DOWN TO REDRAW THE SCREEN BEFORE ZOOMING. THE FOLLOWING RESPONDS WELL WHEN THERE IS MOUSE MOVEMENT TO RETRIGGER ZOOMING.

            If e.Button = MouseButtons.Left Then 'HOLD DOWN LEFT MOUSE BUTTON AND SCOOT MOUSE UP OR DOWN TO ZOOM IN AND OUT. ZOOMING IN AND OUT
                'IS ALWAYS RELATIVE TO CENTER SCREEN AND THE X,Y POSITION OF CURSOR, OTHERWISE IT LOOKS LIKE A FLY-BY.
                Dim yVAL As Single = e.Y 'WAS e.Delta (DELTA IN PHYSICS, STATISTICS, CHEMISTRY, AND ESPECIALLY AMERICA AND EUROPE,ETC. is THE "CHANGE" OF STATE! REQUIRES 'SIGNED' INTEGER TO BE SENT FROM DRIVER, HOWEVER; I THINK MICROSOFT DROPPED THE BALL HERE. DELTA ALWAYS POSITIVE!!
                If yVAL > Me.Height / 2 Then ' BECAUSE MY APP IS GDI+ WITH TRANSLATION TRANSFORM (ROTATED 180), YOU NEED MAY TO REVERSE FOR YOUR APP
                    ' BY USING < AS OPPOSED TO >. WHEN WRITTEN CORRECTLY, GDI+ IS "GREASED LIGHTNING".
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    Zoomval = Zoomval - (0.2 * Zoomval * ZoomOutInc) 'NEWER MICE HAVE 1000DPI, SO ZOOMOUTINC IS A FACTOR SET BY OPERATOR TO SMOOTH ZOOMING.
                    If Zoomval <= 0.1 Then Zoomval = 0.1
                    PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                    PrevYmouse = Me.Height / 2
                    MouseReEntryF = 0 'WAS 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    TrapFormPaintF = 1
                    Exit Sub
                Else
                    'lblMouseXY.Text = "Scrolled UP"
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    Zoomval = Zoomval + (0.2 * Zoomval * ZoomIncrement)
                    If Zoomval > 500 Then Zoomval = 500
                    PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                    PrevYmouse = Me.Height / 2
                    MouseReEntryF = 0 'WAS 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    MouseReEntryF = 0
                    TrapFormPaintF = 1
                    Exit Sub
                End If
            End If
            Try 'OTHERWISE HANDLE GRAPHICS CURSOR AND GRAPHICS OBJECTS
                Dim Mouse_Ydiff As Single = 0
                Dim X As Single = e.X 'mouse location in x
                Dim Y As Single = e.Y 'mouse location in y
                If X = MMx And Y = MMy Then 'Exit Sub for lack of movement. There is another similar feature later if MoveX and MoveY are zero.
                    Exit Sub
                Else
                    MMx = X
                    MMy = Y
                End If ............

        'USE MOUSE DOWN TO DRAW SCREEN IN THE AREA OF INTEREST FIRST

     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim Button As Single = e.Button
            Select Case Button
                Case Is = 1048576.0 'left click
    DoItAgain:
                    'Zoomval = Zoomval + 0.1
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    PrevScreenX = 0
                    PrevScreenY = 0
                    MouseReEntryF = 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    TrapFormPaintF = 1

    May be this should be kicked up to Microsoft, or, its description of e.Delta could possibly be more descriptive. Mouse Wheel does not seem to work for the same reason. It reports the position of the cursor to screen, and not the change in clicks to allow the programmer to handle the response appropriately as needed by the application.

    Frank


    • Edited by fmpeck Friday, January 26, 2018 2:01 PM
    • Marked as answer by fmpeck Friday, January 26, 2018 2:02 PM
    Friday, January 26, 2018 1:57 PM

All replies

  • Why not use the mouse wheel?

    Try to design things that use the normal windows things you will save yourself a lot of headaches.

    Otherwise I would say it calls for a timer. Set a flag in mousedown, start the timer, in mouse up turn off the timer and flag. However if the mouse up is not called or lost then what etc.

    What are you zooming? A drawing? Text? Explain more.

    Wednesday, January 17, 2018 4:09 PM
  • Thank you sincerely for your reply. 

    The Mouse Wheel is a good suggestion, but doesn't work on laptops with touchpads. I didn't not review all of the modes, but it was moot anyway because I couldn't get the touchpad to respond like a mouse wheel easily. If I hold the left touchpad equivalent of mouse left click and scroll with another finger, I can compare the cursor location to the center of the screen and determine zoom in or out, however; subtle difference in finger pressure while holding the left click trigger re-centering the screen, and no available setting in sensitivity helped. There was a problem with reversal of direction.

    I'm drawing directly on the Windows form using GDI +, much like any CAD package.

    Wednesday, January 17, 2018 5:12 PM
  • Thank you sincerely for your reply. 

    The Mouse Wheel is a good suggestion, but doesn't work on laptops with touchpads. I didn't not review all of the modes, but it was moot anyway because I couldn't get the touchpad to respond like a mouse wheel easily. If I hold the left touchpad equivalent of mouse left click and scroll with another finger, I can compare the cursor location to the center of the screen and determine zoom in or out, however; subtle difference in finger pressure while holding the left click trigger re-centering the screen, and no available setting in sensitivity helped. There was a problem with reversal of direction.

    I'm drawing directly on the Windows form using GDI +, much like any CAD package.

    UhHuh. :)

    Like I say. use the things normally as they are designed to work and save yourself a lot of headache.

    How about a scrollbar? Zoomin fence etc? Also shift+ ctrl+ etc.

    Why does the pad not respond to the proper mouse wheel functions? Broken? Bad code?

    You sound fairly smart. What is your skill level? Do you understand how to use mousedown and then while mousedown handle mousemove and after mouseup do nothing?

    Actually, see if you follow how this example works and then see if you can adapt it.

    There are lots of ways...

    ...maybe similar to drawing the rect in the example but use RMB and drag up to zoom in, down to zoom out? Use the rmb mousedown to save the click cords and center the zoom in mouse move on the mousedown point.

    'draw rectangle move with mouse 
    Option Strict On
    Public Class CADMouseRectangle
        Private WithEvents PictureBox1 As New PictureBox With {.Parent = Me, .Dock = DockStyle.Fill, .BackColor = Color.Black}
        Private MouseDownStage As Integer
        Private MouseDownPt, MouseMovePt, MouseDownOffsetPt As PointF
        Private FenceRect As RectangleF
    
    
        Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
            MouseDownStage = GetMouseOverType(e.X, e.Y)
            Select Case MouseDownStage
                Case 1      'nothing under mouse down begin drawing tracer
                    MouseDownPt = e.Location
                    MouseMovePt = e.Location
                Case 2, 3   'mouse down on rectangle or handle begine moving
                    MouseDownPt = FenceRect.Location
                    MouseDownOffsetPt.X = e.X - FenceRect.X
                    MouseDownOffsetPt.Y = e.Y - FenceRect.Y
            End Select
        End Sub
    
        Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
            MouseMovePt = e.Location
    
            If MouseDownStage > 0 Then
                Dim dx, dy As Single
    
                Select Case MouseDownStage
                    Case 1                      'drawing rectangle 
                        FenceRect = GetFenceRect(MouseDownPt, New SizeF(MouseMovePt.X - MouseDownPt.X,
                                                                        MouseMovePt.Y - MouseDownPt.Y))
    
                    Case 2                      'moving fence
                        dx = e.X - MouseDownPt.X
                        dy = e.Y - MouseDownPt.Y
                        FenceRect.X = MouseDownPt.X + dx - MouseDownOffsetPt.X
                        FenceRect.Y = MouseDownPt.Y + dy - MouseDownOffsetPt.Y
                    Case 3                      'moving handle
                        FenceRect.Width = Math.Abs(FenceRect.X - e.X)
                        FenceRect.Height = Math.Abs(FenceRect.Y - e.Y)
                End Select
                PictureBox1.Invalidate()
            Else
                Select Case GetMouseOverType(e.X, e.Y)
                    Case 2  'fence
                        Cursor = Cursors.Hand
                    Case 3 'handle
                        Cursor = Cursors.SizeNESW
                    Case Else
                        Cursor = Cursors.Default
                End Select
            End If
        End Sub
    
        Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
    
            Select Case MouseDownStage
                Case 1      'save the rectangle
                    FenceRect = GetFenceRect(MouseDownPt, New SizeF(MouseMovePt.X - MouseDownPt.X,
                                                                        MouseMovePt.Y - MouseDownPt.Y))
    
            End Select
    
            MouseDownStage = 0
            PictureBox1.Invalidate()
        End Sub
    
        Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
    
            With e.Graphics
                Using p As New Pen(Color.White, 1)
                    'draw the saved rectangle
                    If FenceRect.Width > 0 Then
                        'rectangle outline dashed white
                        p.DashStyle = Drawing2D.DashStyle.Dash
                        .DrawRectangle(p, Rectangle.Round(FenceRect))
    
                        'draw the handle solid green
                        Dim h As Integer = 5
                        Dim rect2 As New Rectangle(CInt(FenceRect.X + FenceRect.Width - h), CInt(FenceRect.Y + FenceRect.Height - h), 2 * h, 2 * h)
                        p.Width = 2
                        p.Color = Color.LimeGreen
                        p.DashStyle = Drawing2D.DashStyle.Solid
                        .DrawRectangle(p, rect2)
                    End If
                End Using
            End With
        End Sub
    
        Private Function GetMouseOverType(x As Integer, y As Integer) As Integer
            'determine if the mouse pointer is over the handle or fence
            Dim h As Integer = 5
            Dim handleRect As New Rectangle(CInt(fenceRect.X + fenceRect.Width - h), CInt(fenceRect.Y + fenceRect.Height - h), 2 * h, 2 * h)
    
            If handleRect.Contains(x, y) Then
                GetMouseOverType = 3              'mouse over handle
            ElseIf fenceRect.Contains(x, y) Then
                GetMouseOverType = 2              'mouse over fence FenceRect
            Else
                GetMouseOverType = 1              'mouse not over anything
            End If
        End Function
    
        Private Function GetFenceRect(locPt As PointF, sz As SizeF) As RectangleF
            'creates proper FenceRect from any direction for point and size 
            Dim X As Single = locPt.X
            Dim X1 As Single = sz.Width
    
            If X1 < 0 Then
                X1 = Math.Abs(X1)
                X -= X1
            End If
    
            Dim Y As Single = locPt.Y
            Dim Y1 As Single = sz.Height
    
            If Y1 < 0 Then
                Y1 = Math.Abs(Y1)
                Y -= Y1
            End If
    
            GetFenceRect = New RectangleF(X, Y, X1, Y1)
    
        End Function
    End Class

     


    Wednesday, January 17, 2018 5:34 PM
  • Copied from https://anydifferencebetween.com/difference-between-touchpad-and-mouse/

    Touchpad

    A touchpad is a small, flat, rectangular pointing device that is sensitive to pressure and motion. To move the pointer using a touchpad, slide your fingertip across the surface of the pad. Some touchpads have one or more buttons around the edge of the pad that work like mouse buttons. On most touchpads, you also can tap the pad’s surface to imitate mouse operations such as clicking. Touchpads are found most often on notebook computers, including netbooks and many Tablet PCs.

    Mouse

    A mouse is a pointing device that fits comfortably under the palm of your hand. With a mouse, users control the movement of the pointer. As you move a mouse, the pointer on the screen also moves. Generally, you use the mouse to move the pointer on the screen to an object such as a button, a menu, an icon, a link, or text. Then, you press a mouse button to perform a certain action associated with that object.

    Most desktop computer users today have some type of optical mouse, which uses devices that emit and sense light to detect the mouse’s movement. Some use optical sensors, and others use a laser. The latter, often referred to as a laser mouse, usually is more expensive than the former.

    Perhaps you could change the Touchpad settings with code when your app launches and change them back when it exits. This link Changing Mouse Settings With VB.NET is for mouse but may reflect for touchpad too. I found this link c# - Win32 API function to programmatically enable/disable device talking about SetupDiGetClassDevs but I did not read into it much.


    La vida loca

    Wednesday, January 17, 2018 5:39 PM
  • -deleted cause sometimes I'm stupid too!-


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Wednesday, January 17, 2018 6:07 PM
    Moderator
  • Great code. Customer hates what we used to call the "zoom cube." Too many clicks and iterations of cube to get to a final "magnification". The graphics is so fast in my app, it looks like a zoom function on a camera, and you can zoom to 0.0001" out to 1/20 scale very fast. At the very small scale, the zoom cube requires 10 or more times to achieve the same result. (I added CTRL + and CTRL- in the Key_Down, and that works great because the key strobes (repeat key) right back to the Key Down in milliseconds. Looks continuously differentiable to the reference target making it easy for the operator to inspect.) As I read your code, it requires moving the mouse cursor as the primary event, and that works on my example as well. What the customer wants is to simply press the left mouse button to zoom in, and the right mouse button to zoom out, much like "repeat key" works in Key_Down. There is no "strobe" or timer for the mouse events like there is for the keyboard. A formal timer would not be needed as code execution shoots through the events. A simple "flag" and possible counter would redirect back to mouse_move. For instance the flag would be set to zero as the code execution lands on Mouse_CaptureChange fires. Execution of a mouse event may go back to the windows form, for instance. If I knew the block from whence a mouse_event came into existence, and where the event goes after Mouse_Move, I could probably solve it.  
    Wednesday, January 17, 2018 6:37 PM
  • Thanks for the reply. Programmatically, the only difference between the touchpad and the mouse is the device itself. Whoever wrote the drivers, all of the mouse events are triggered just the same as if it were an old style mouse. Fundamentally, the keyboard has a "repeat key" strobe that the mouse lacks. I was trying to set a flag and counter to test for button down though out the event chain of all of the events, and simply call the mouse move event once again. I would remove the flag when the button came back up. I can't seem to find where the mouse event "chain of command" ends. Possibly back to the form itself? The Visual Studio editor's F8 seems to lead to no where.
    Wednesday, January 17, 2018 6:47 PM
  • Here is a simple nothing fancy timer example.

    Public Class Form5 Private WithEvents timer1 As New Timer With {.Enabled = True, .Interval = 100} Private MouseState, MouseCount As Integer Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load DoubleBuffered = True End Sub Private Sub Form5_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown If e.Button = MouseButtons.Left Then MouseState = 1 Else MouseState = 2 End If Invalidate() End Sub Private Sub Form5_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp MouseState = 0

    End Sub Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint Select Case MouseState Case 1 'lmb e.Graphics.Clear(Color.Blue) Case 2 'rmb e.Graphics.Clear(Color.Green) Case Else e.Graphics.Clear(Color.DimGray) End Select e.Graphics.DrawString(MouseCount.ToString, New Font("tahoma", 14, FontStyle.Bold), Brushes.AntiqueWhite, 100, 100) End Sub Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick If MouseState > 0 Then Select Case MouseState Case 1 'lmb MouseCount += 1 Case 2 'rmb MouseCount -= 1 End Select Invalidate() End If End Sub End Class


    PS Hi Monkey!



    • Edited by tommytwotrain Wednesday, January 17, 2018 7:42 PM color, mousestate
    Wednesday, January 17, 2018 7:09 PM
  • Thank you Reed,

    I moved the code into the MouseDown, however; it fired only one time. Am I missing something?

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim Button As Single = e.Button
            Select Case Button
                Case Is = 1048576.0 'left click
                    'Zoomval = Zoomval + 0.01
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    PrevScreenX = 0
                    PrevScreenY = 0
                    MouseReEntryF = 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                Case Is = 2097152.0 'right click

    Wednesday, January 17, 2018 7:42 PM
  • Thank you Reed,

    I moved the code into the MouseDown, however; it fired only one time. Am I missing something?

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim Button As Single = e.Button
            Select Case Button
                Case Is = 1048576.0 'left click
                    'Zoomval = Zoomval + 0.01
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    PrevScreenX = 0
                    PrevScreenY = 0
                    MouseReEntryF = 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                Case Is = 2097152.0 'right click

    Wow, sorry about that, I'm not having much luck today!

    I don't know what I was thinking... I've been working with my own input library lately and it works that way so I guess I confused myself.  Been working with a continuously running program loop for too long. :P

    OK so, another option would be to start a timer that calls the zoom code.  Have the MouseDown event set the scale factor (+/-) and start the timer.  The Timer.Tick event handler will execute the code, zooming whichever way the factor is set.  Then have the MouseUp event handler turn off the timer.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, January 17, 2018 7:50 PM
    Moderator
  • REED,

    Thank you for all your efforts. Below is some VB code using Mouse_Move and Mouse_Down. When operator clicks Mouse_Down, the initial screen is drawn. (That code is shown after Mouse_Move code shown below.) e.Delta does not work if the mouse driver does not submit a signed integer. It is always positive. Programmers have a different expectation than operators, and my interpretation of what e.Delta should be doing may have been the problem, but if you read MSDS descriptions, I still think I'm right. This may explain all of the bugs reported on the internet about mouse functions not working. Below is my work-around that uses the Center of the Screen and e.Y to interpret what the operator is requesting.  

     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

            'e.Delta DOES NOT SUBMIT NEGATIVE NUMBERS!!! IT IS NOT RELATIVE. THEREFORE USE CENTER SCREEN POSITION TO INTERPRET OPERATOR'S MOVEMENT

            'PLACING THE ZOOMING CODE AHEAD OF CURSOR MOVEMENT CODE PREVENTS THE CENTER SCREEN OBJECT POSITION OF INTEREST FROM CHANGING BY USE OF EXIT SUB

            'LET UP ON MOUSE AND MOVE CURSOR TO 'ADJUST' POSITION OF INTEREST, HOLD LEFT MOUSE DOWN, AND ZOOM FURTHER AS DESIRED. USE MOUSE DOWN TO REDRAW THE SCREEN BEFORE ZOOMING. THE FOLLOWING RESPONDS WELL WHEN THERE IS MOUSE MOVEMENT TO RETRIGGER ZOOMING.

            If e.Button = MouseButtons.Left Then 'HOLD DOWN LEFT MOUSE BUTTON AND SCOOT MOUSE UP OR DOWN TO ZOOM IN AND OUT. ZOOMING IN AND OUT
                'IS ALWAYS RELATIVE TO CENTER SCREEN AND THE X,Y POSITION OF CURSOR, OTHERWISE IT LOOKS LIKE A FLY-BY.
                Dim yVAL As Single = e.Y 'WAS e.Delta (DELTA IN PHYSICS, STATISTICS, CHEMISTRY, AND ESPECIALLY AMERICA AND EUROPE,ETC. is THE "CHANGE" OF STATE! REQUIRES 'SIGNED' INTEGER TO BE SENT FROM DRIVER, HOWEVER; I THINK MICROSOFT DROPPED THE BALL HERE. DELTA ALWAYS POSITIVE!!
                If yVAL > Me.Height / 2 Then ' BECAUSE MY APP IS GDI+ WITH TRANSLATION TRANSFORM (ROTATED 180), YOU NEED MAY TO REVERSE FOR YOUR APP
                    ' BY USING < AS OPPOSED TO >. WHEN WRITTEN CORRECTLY, GDI+ IS "GREASED LIGHTNING".
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    Zoomval = Zoomval - (0.2 * Zoomval * ZoomOutInc) 'NEWER MICE HAVE 1000DPI, SO ZOOMOUTINC IS A FACTOR SET BY OPERATOR TO SMOOTH ZOOMING.
                    If Zoomval <= 0.1 Then Zoomval = 0.1
                    PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                    PrevYmouse = Me.Height / 2
                    MouseReEntryF = 0 'WAS 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    TrapFormPaintF = 1
                    Exit Sub
                Else
                    'lblMouseXY.Text = "Scrolled UP"
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    Zoomval = Zoomval + (0.2 * Zoomval * ZoomIncrement)
                    If Zoomval > 500 Then Zoomval = 500
                    PrevXmouse = Me.Width / 2 'this should keep centered while left mouse button is down.
                    PrevYmouse = Me.Height / 2
                    MouseReEntryF = 0 'WAS 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    MouseReEntryF = 0
                    TrapFormPaintF = 1
                    Exit Sub
                End If
            End If
            Try 'OTHERWISE HANDLE GRAPHICS CURSOR AND GRAPHICS OBJECTS
                Dim Mouse_Ydiff As Single = 0
                Dim X As Single = e.X 'mouse location in x
                Dim Y As Single = e.Y 'mouse location in y
                If X = MMx And Y = MMy Then 'Exit Sub for lack of movement. There is another similar feature later if MoveX and MoveY are zero.
                    Exit Sub
                Else
                    MMx = X
                    MMy = Y
                End If ............

        'USE MOUSE DOWN TO DRAW SCREEN IN THE AREA OF INTEREST FIRST

     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim Button As Single = e.Button
            Select Case Button
                Case Is = 1048576.0 'left click
    DoItAgain:
                    'Zoomval = Zoomval + 0.1
                    ScreenX = Xcursor
                    ScreenY = Ycursor
                    PrevScreenX = 0
                    PrevScreenY = 0
                    MouseReEntryF = 1
                    DrawCursorOnlyF = 0
                    RedrawScreen()
                    TrapFormPaintF = 1

    May be this should be kicked up to Microsoft, or, its description of e.Delta could possibly be more descriptive. Mouse Wheel does not seem to work for the same reason. It reports the position of the cursor to screen, and not the change in clicks to allow the programmer to handle the response appropriately as needed by the application.

    Frank


    • Edited by fmpeck Friday, January 26, 2018 2:01 PM
    • Marked as answer by fmpeck Friday, January 26, 2018 2:02 PM
    Friday, January 26, 2018 1:57 PM

  • May be this should be kicked up to Microsoft, or, its description of e.Delta could possibly be more descriptive. Mouse Wheel does not seem to work for the same reason. It reports the position of the cursor to screen, and not the change in clicks to allow the programmer to handle the response appropriately as needed by the application.

    Frank



    Yes the doc for delta here is almost worthless I made a comment to that effect in the Helpful? thing.

    https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k%28System.Windows.Forms.MouseEventArgs.Delta%29%3Bk%28TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5.2%29%3Bk%28DevLang-VB%29&rd=true&f=255&MSPPError=-2147217396

    Is that what you mean?

    e.delta only makes sense in the mousewheel event. Something the docs fail to mention?

    Here is an example of using mousewheel. btw the form must have focus to get the event.

    Note the example only uses e.delta for the sign of the direction. The actual value amount is sort of useless for most things I have found.

    Public Class Form7
    
        Private RectSize As Integer = 100
    
        Private Sub Form7_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
    
            RectSize += 10 * Math.Sign(e.Delta)
            If RectSize > 200 Then RectSize = 200
            If RectSize < 10 Then RectSize = 10
            Invalidate()
    
        End Sub
    
        Private Sub Form7_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            e.Graphics.DrawRectangle(New Pen(Color.Red, 4), 20, 20, RectSize, RectSize)
    
        End Sub
    End Class


    PS. Note here in the mousewheel doc they use

    e.delta * MouseWheelScrollLines

    and mousewheel event to scroll a textbox.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousewheel%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    And in here it shows the MouseWheelScrollLines is a windows system property. You can set scroll speed for your mouse if it has that feature.


    https://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.mousewheelscrolllines(v=vs.110).aspx

    Friday, January 26, 2018 3:21 PM