Click here to Skip to main content
13,053,276 members (58,882 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 2 Jun 2005

MoyStick, a Joystick Control

, 2 Jun 2005
Rate this:
Please Sign up or sign in to vote.
An eight direction joystick control.

Sample Image


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

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();
        case MoyStick.cPoint.north:
            dY = e.Magnitude * (-1);
            dX = 0;
        case MoyStick.cPoint.northEast:
            dY = e.Magnitude * (-1);
            dX = e.Magnitude;
        //(And so on......)

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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralPocket PC Pin
H.Riazi24-Nov-06 23:41
memberH.Riazi24-Nov-06 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 3 Jun 2005
Article Copyright 2005 by yob25
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid