|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
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
IntroductionHi 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: Hope, you'll find this useful. Roey
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||