PDA

Click to See Complete Forum and Search --> : [RESOLVED] Problem Overriding OnMouseMove


Hamish
Feb 9th, 2009, 08:16 AM
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 (http://www.vbforums.com/showthread.php?t=463553&highlight=picturebox_colormap) control for use with a Canvas)

I've got the following 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? :confused:

chris128
Feb 9th, 2009, 08:31 AM
Instead of this:
Protected Overrides Sub OnMouseMove(ByVal e As MouseButtonEventArgs)
try this:
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Input.MouseEventArgs)

Hamish
Feb 9th, 2009, 08:41 AM
Nope... same error. I have imported the System.Windows.Input namespace, but even specifying the fully qualified type does not solve the problem.

chris128
Feb 9th, 2009, 08:44 AM
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?

Hamish
Feb 9th, 2009, 08:48 AM
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. :)

chris128
Feb 9th, 2009, 08:49 AM
thought you might of missed that :P Glad its sorted :)