Click here to Skip to main content
5,787,682 members and growing! (20,654 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Beginner License: The Code Project Open License (CPOL)

Cool Angle Select Control (Photoshop style)

By Roey C

A cool control to select Angles.
C# (C# 1.0, C# 2.0, C# 3.0, C#), .NET (.NET, .NET 3.5, .NET 3.0, .NET 1.0, .NET 1.1, .NET 2.0), Win32

Posted: 29 Jul 2006
Updated: 13 Nov 2008
Views: 13,982
Bookmarked: 10 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 2.05 Rating: 2.27 out of 5
5 votes, 62.5%
1
0 votes, 0.0%
2
1 vote, 12.5%
3
0 votes, 0.0%
4
2 votes, 25.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Angle Select Control

Introduction

Hi everybody! this is the first time i decided to release a code of mine on codeproject. it's quite straight forward, i don't have much to say about it, and i think the picture above describe it pretty 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 the code below shows:

/// <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 the events to use:

FillColor - Sets the Circle's fill color.
LineColor - Sets the Circles's line color.
angleChanged - (event) Called when ever the user is changing the Angle.
Angle - Sets or Gets the angle of the control.

Hope, you'll find this useful.

Roey

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


Hi my name is Roey,
I've been programing for something like 3 years.
My favourites technologies are Win32API and C#.
These days i'm looking for a job as a programmer, and mean while i'm just enjoying doing nothing... Smile
Occupation: Web Developer
Location: Israel Israel

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralBroken LinkmemberGraemeg3319:21 29 Jul '06  
GeneralRe: Broken LinkmemberRoey C22:40 29 Jul '06  
GeneralRe: Broken LinkmemberRoey C22:47 29 Jul '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Nov 2008
Editor:
Copyright 2006 by Roey C
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project