Click here to Skip to main content
Licence CPOL
First Posted 29 Jul 2006
Views 22,805
Downloads 180
Bookmarked 13 times

Cool Angle Select Control (Photoshop style)

By Roey C | 13 Nov 2008
A cool control to select angles.
4 votes, 57.1%
1

2
1 vote, 14.3%
3

4
2 votes, 28.6%
5
2.11/5 - 7 votes
μ 2.11, σa 3.33 [?]

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Roey C

Software Developer (Senior)

Israel Israel

Member
Hi my name is Roey,
 
new: long time has passed since i wrote my previous biography...
since then i founded a new start-up company: www.blossom-kc.com
and finished my B.S.c degree in Computer science.
 
Feel free to write me on any subject... i promise, i won't byte! Smile | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralBroken Link PinmemberGraemeg3319:21 29 Jul '06  
GeneralRe: Broken Link PinmemberRoey C22:40 29 Jul '06  
GeneralRe: Broken Link PinmemberRoey C22:47 29 Jul '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120209.1 | Last Updated 13 Nov 2008
Article Copyright 2006 by Roey C
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid