First of all, you do not access the variable (field or other member) of the class. As you never use any
static members here, you're trying to access a member of an
instance of the class; and this is the key.
You access the instance
CvPoint cursorpos
correctly, but your problem is modification of it. I don't know if
CvPoint
a class or a structure. Is this is a structure, modification won't work. Why? Structure (
struct
) is a value type. When you assign
newcurpose
, you get a copy of your instance's data and then you
modify a copy. No wonder, the data of the instance
pupilobj
is not modified. To make is working as is, you need to make the type
CvPoint
a class.
Using the class CvPoint
instead of structure is one solution. Another solution would be using structure but writing back the of the data to the
pupilobj
. In other words, create one more method called
SetCursorPos
. But don't rush. Let's make another improvement.
You should better make the
CursorPos
a property.
You should better make is a property in all cases, even if you make
CvPoint
a class:
public class DetectEye {
public CvPoint CursorPosition { get; set; }
}
or perhaps better
public class DetectEye {
public CvPoint CursorPosition {
get { return mCursorPosition; }
set {
mCursorPosition;
DoSomething();
}
}
CvPoint mCursorPosition = new CvPoint();
}
In this way, you will be able to modify the field from the caller accessing the instance of
DetectEye
.
Now, couple of useful notes. Why you always use
public
? Public is to make access from another assembly is well. Are you sure you need it? If not, use internal
instead
of public,
internal protected
instead of
protected
. Just check up if you yield more access than really required.
Don't use names like "Form1", "label3". They are auto-generated and actually violate (good) Microsoft naming conventions. When you start working with such objects, always rename them to something semantic. Visual Studio re-factoring engine is great help here.
—SA