Morning,
I'm just about ready to claw my own eyes out at this point. I'm building a basic image editor using Windows forms on .NET 3.5, and what I need is a 'select tool'. This tool needs to appear when a button is clicked and will be a fixed size, it needs to be a drag and dropable rectangle with a transparent center.
The purpose of this is to act almost like a 'Picture frame' in that the user can drag and drop the rectangle over a portion of the image and hit another button to snapshot whatever is inside the rectangle at that point. (Please note: I don't want a rubber band rectangle, it has to be a fixed size, draggable across the form and transparent).
I've spent a couple of days scouring the internet and this site looking for possible solutions, none of which have been any use. I have managed to make a control draggable - but this poses problems with transparency. Below is the code which makes a control draggable, but I'm not sure this is the right path to take.
class ControlMover
{
public enum Direction
{
Any,
Horizontal,
Vertical
}
public static void Init(Control control)
{
Init(control, Direction.Any);
}
public static void Init(Control control, Direction direction)
{
Init(control, control, direction);
}
public static void Init(Control control, Control container, Direction direction)
{
EditorForm.blnSelectArea = true;
bool Dragging = false;
Point DragStart = Point.Empty;
control.MouseDown += delegate(object sender, MouseEventArgs e)
{
Dragging = true;
DragStart = new Point(e.X, e.Y);
control.Capture = true;
};
control.MouseUp += delegate(object sender, MouseEventArgs e)
{
Dragging = false;
control.Capture = false;
};
control.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (Dragging)
{
if (direction != Direction.Vertical)
container.Left = Math.Max(0, e.X + container.Left - DragStart.X);
if (direction != Direction.Horizontal)
container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y);
control.Invalidate();
}
};
}
}
Can anyone point me in the right direction or make a suggestion as to where to look.
Many Thanks