
Introduction
This control emulates an eight direction joystick. Unlike conventional joysticks, this control also provides a magnitude measurement depending on how far the end of the "stick" is from the center of the control.
Using the code
Attributes you may want to be aware of:
BackColor sets the color of the control's circular region.
CircleDiameter sets the diameter (in pixels) of the control.
LineColor sets the color of the control's "stick".
LineShapeEnd sets the shape of the end of the "stick".
LineWidth sets the width of the "stick" (in pixels).
Using the mouse stick with your app requires the use of the MouseStickMoved event. The eventargs provides two attributes, Magnitude and Direction.
Magnitude will return an integer value between 0 and 15, depending on the distance between the end of your "stick" and the center of the control.
Direction returns an enumeration of type cPoint, which is defined as follows: public enum cPoint
{
north,
northEast,
east,
southEast,
south,
southWest,
west,
northWest
}
For example, in my demo program, I set my circle's acceleration and direction in the form's userControl11_MouseStickMoved event handler:
private void userControl11_MouseStickMoved(object sender,
MoyStick.MouseStickEventArgs e)
{
stbMouseStick.Text = "direction: " + e.Direction.ToString() +
" magnitude: " + e.Magnitude.ToString();
switch(e.Direction)
{
case MoyStick.cPoint.north:
dY = e.Magnitude * (-1);
dX = 0;
break;
case MoyStick.cPoint.northEast:
dY = e.Magnitude * (-1);
dX = e.Magnitude;
break;
Points of Interest
I used a timer to invalidate to eliminate intense flickering that I observed when I tried to invalidate every time the MouseMove event occurred.