Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Cool Angle Select Control (Photoshop style)

0.00/5 (No votes)
13 Nov 2008 1  
A cool control to select angles.

Angle Select Control

Introduction

This is the first time I have decided to release a code of mine on CodeProject. It's quite straightforward, I don't have much to say about it, and I think the picture above describes it well. well.

Basically, I needed a control to select an angle, and I made the one above. I saw the one used on Photoshop and decided to create one of my own.

The implementation is really simple, as is shown in the code below:

/// <summary>
/// Event - User is moving the mouse.
/// </summary>

private void AngleSelect_MouseMove(object sender, MouseEventArgs e)
{
    if (Clicked == true)
    {
        //if mouse down, change the Angle.
        Point centerPoint = new Point(ClientRectangle.Width / 2, 
                                      ClientRectangle.Height / 2);
        Point mousePos = ((MouseEventArgs)e).Location;
        //Using the Atan2 function in order to get the Angle 
        //of the Slope between the center Point
        // of the control and the Mouse Point.
        double radians = Math.Atan2(mousePos.Y - centerPoint.Y, 
                                    mousePos.X - centerPoint.X);
        //Then converting from Radians to regular Units.
        angle = (int)(radians * (180 / Math.PI));
        Refresh();
        //call delegated function
        try
        {
            angleChanged(angle);
        }
        catch { }
    }
}

Here are the main properties and the events to use:

  • FillColor - Sets the circle's fill color.
  • LineColor - Sets the circle's line color.
  • Angle - Sets or gets the angle of the control.
  • AngleChanged - Called whenever the user is changing the angle.

Hope, you'll find this useful.

License

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