Cursor Position issue...

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
In a few forms in my app, (for demo purposes), I momentarily take control of the mouse cursor, and I use the following statements:
VB.NET:
CurPos = Cursor.Current.Position
This generates a warning in the IDE, I presume to mean that the current cursor position cannot be evaluated while in the IDE. This is fine, and I understand why this is the case. The issue is that other warnings may be obscured by all of these cursor position warnings. I also tend to shut off the display of warnings due to these cursor position related warnings, and that truely does obscure any other warnings that I would like to be aware of. Is there a different way to accomplish the same thing (CurPos = Cursor.Current.Position) that will not generate these warnings?
 
the warning says
Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
What it means is it will ignore incorrect usage like calling instance.sharedmember() and call class.sharedmember() anyway because that's the only way to call a shared member.

Change code to: Cursor.Position
which has the same meaning as: System.Windows.Forms.Cursor.Position
 
I'm sorry John, I don't quite understand your post. Are you saying that the warnings cannot be avoided here?
I have changed the code to "CurPos = Cursor.Position", and the same warnings are generated.
 
"CurPos = Cursor.Position"
I don't get a warning for that code.
Me.Cursor.Position
I get a warning for that code.

Position property is shared, so you don't qualify it with an instance of Cursor class.
 
As far as the compiler goes it makes no difference. The shared member is the position property so in fact the me.cursor bit can be correct. The compiler is simply warning that the user may be mis-understanding the code.

VB.NET:
System.Windows.Forms.Cursor.Position

Will not raise any error as you are using the fully qualified namespace for the shared member.
 
You are correct it makes no difference for the compiler, because it will call the shared member the only way possible; ie disregarding the instance you qualified it by. But the IDE give this warning so you can write the code correctly and not get the warning. Interestingly it will also give the warning if you try to qualify the shared member by a Cursor type variable that hasn't yet been assigned an instance (Nothing), it will in other words not check if the qualifier actually is an instance, only that it fits a namespace path or not.
 
Thanx for the help. I was able to clear my warnings slate with:
VB.NET:
 System.Windows.Forms.Cursor.Position
The reason I was still getting the warnings because I changed my code to
VB.NET:
 System.Windows.Forms.Cursor.Current.Position
I didn't understand that the term "Current" needed to be excluded. 'Wonder why Intellesense includes that option???
 
Back
Top