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:
private void AngleSelect_MouseMove(object sender, MouseEventArgs e)
{
if (Clicked == true)
{
Point centerPoint = new Point(ClientRectangle.Width / 2,
ClientRectangle.Height / 2);
Point mousePos = ((MouseEventArgs)e).Location;
double radians = Math.Atan2(mousePos.Y - centerPoint.Y,
mousePos.X - centerPoint.X);
angle = (int)(radians * (180 / Math.PI));
Refresh();
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.