This is easily done by adding three mouse events (label.MouseDown, label.MouseUp, label.MouseMove)
MouseDown :: When the mouse button goes down, based on the location of the mouse (it is on the edge of the label or inside it), it determines whether the target is moving or resizing, and it is stored in two variables (_moving, _resizing).
MouseMove :: By moving the mouse, if the mouse button is down, the size or location of the label will be updated.
MouseUp :: When the mouse button is upend, the variables are false.
public class Ulabel
{
public System.Windows.Forms.Label label;
public UTask(string title, Color color, int Lno)
{
label = new System.Windows.Forms.Label();
label.Text = title;
label.BackColor = color;
label.Name = "T" + Lno.ToString();
label.AutoSize = false;
label.Size = new Size(20, 50);
label.Location = new Point(50, 50);
Init();
}
private bool _moving;
private bool _resizing;
private Point _cursorStartPoint;
private Point _cursorStartPointmove;
private Point _cursorLast;
private int _Initwidth;
private bool MouseIsInRightEdge;
int count_call = 0;
internal void Init()
{
_moving = false;
_resizing = false;
_moveIsInterNal = false;
_cursorStartPoint = Point.Empty;
_cursorStartPointmove = Point.Empty;
MouseIsInRightEdge = false;
label.MouseDown += (sender, e) => MouseDown(label, e);
label.MouseUp += (sender, e) => MouseUp(label);
label.MouseMove += (sender, e) => MouseMove(label, e);
}
private void UpdateMouseEdgeProperties(Control control, Point mouseLocationInControl)
{
MouseIsInRightEdge = Math.Abs(mouseLocationInControl.X - control.Width)
0 comments:
Post a Comment
Thanks