Results 1 to 8 of 8

Thread: [RESOLVED] Problem Overriding OnMouseMove

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Resolved [RESOLVED] Problem Overriding OnMouseMove

    I'm creating a "ColorMap Canvas", i.e. a canvas where clicking the Canvas will return the color of the corresponding picture. (I'm actually adapting Atheist's PictureBox_ColorMap control for use with a Canvas)

    I've got the following code:
    Code:
    Protected Overrides Sub OnMouseMove(ByVal e As MouseButtonEventArgs)
       Dim p As System.Windows.Point = e.GetPosition(Me)
       MyBase.OnMouseMove(e)
       If _RaiseEventOnMouseMove Then
          If Not _ColorMap Is Nothing AndAlso p.X <= _ColorMap.Width AndAlso p.Y <= _ColorMap.Height Then
             RaiseEvent ColorMapMouseMove(Me, _ColorMap.GetPixel(CInt(p.X), CInt(p.Y)))
          Else
             RaiseEvent ColorMapMouseMove(Me, Nothing)
          End If
       End If
    End Sub
    The IDE gives me the error:
    "sub 'OnMouseMove' cannot be declared 'Overrides' because it does not override a sub in a base class."

    When I remove the keyword "Overrides" I get the error:
    "sub 'OnMouseMove' shadows an overridable method in the base class 'UIElement'. To override the base method, this method must be declared 'Overrides'."

    What's going on here? Why can't I override OnMouseMove? Is my IDE suffering from schizophrenia?

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Problem Overriding OnMouseMove

    Instead of this:
    vb Code:
    1. Protected Overrides Sub OnMouseMove(ByVal e As MouseButtonEventArgs)
    try this:
    vb Code:
    1. Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Input.MouseEventArgs)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Problem Overriding OnMouseMove

    Nope... same error. I have imported the System.Windows.Input namespace, but even specifying the fully qualified type does not solve the problem.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Problem Overriding OnMouseMove

    You are using MouseEventArgs like I suggested and not MouseButtonEventArgs yeah?

    Also, just to clarify, the class that this sub is in is inheriting from the Canvas control yes?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Problem Overriding OnMouseMove

    Brilliant! I hadn't noticed the type difference there. The namespace thing was more obvious....
    Yes, it is inheriting from Canvas, and I have no more errors in the code. Now on to build a test case.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] Problem Overriding OnMouseMove

    thought you might of missed that :P Glad its sorted
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    56

    Re: Problem Overriding OnMouseMove

    Quote Originally Posted by Hamish View Post
    Brilliant! I hadn't noticed the type difference there. The namespace thing was more obvious....
    Yes, it is inheriting from Canvas, and I have no more errors in the code. Now on to build a test case.
    I am having the same error. so what did you do different in your code?

    I know this is a very old thread but anyone that knows a solution to this please help. I will greatly appreciate it

    Public Overrides Sub LoadDataSource()
    Try

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: [RESOLVED] Problem Overriding OnMouseMove

    Your overriding sub must have the exact same types of attributes as the sub you are overriding. In my example, I was overriding:

    Sub OnMouseMove(e As MouseEventArgs)

    with:

    Sub OnMouseMove(e As MouseButtonEventArgs)

    That does not work. So in your case I think the sub LoadDataSource you are overriding has arguments, while the overriding sub you show here does not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width