Click here to Skip to main content
6,304,948 members and growing! (17,932 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), .NET (.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5), Win32
Posted:29 Jul 2006
Updated:13 Nov 2008
Views:16,172
Bookmarked:10 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
8 votes for this article.
Popularity: 2.05 Rating: 2.27 out of 5
5 votes, 62.5%
1

2
1 vote, 12.5%
3

4
2 votes, 25.0%
5

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


Member
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
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
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    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
Web16 | Advertise on the Code Project