-
Feb 9th, 2009, 08:16 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Feb 9th, 2009, 08:31 AM
#2
Re: Problem Overriding OnMouseMove
Instead of this:
vb Code:
Protected Overrides Sub OnMouseMove(ByVal e As MouseButtonEventArgs)
try this:
vb Code:
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Input.MouseEventArgs)
-
Feb 9th, 2009, 08:41 AM
#3
Thread Starter
Hyperactive Member
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.
-
Feb 9th, 2009, 08:44 AM
#4
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?
-
Feb 9th, 2009, 08:48 AM
#5
Thread Starter
Hyperactive Member
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.
-
Feb 9th, 2009, 08:49 AM
#6
Re: [RESOLVED] Problem Overriding OnMouseMove
thought you might of missed that :P Glad its sorted
-
Apr 3rd, 2012, 04:26 PM
#7
Member
Re: Problem Overriding OnMouseMove
Originally Posted by Hamish
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
-
Apr 4th, 2012, 02:59 AM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|