1

I would like to allow the user to click within my UserControl and drag left/right to zoom in/out but I'd like the dragging not to be restricted to the actual control's boundaries. What sort of event or strategy would be the right way to track the mouse position outside the control and the form until the mouse click is released ?

Thanks in advance for any help or advice.

2 Answers 2

3

Set the Capture property to true in a MouseDown event handler. You'll keep getting MouseMove messages, even if the mouse has left the client area.

  public partial class UserControl1 : UserControl {
    public UserControl1() {
      InitializeComponent();
    }
    protected override void OnMouseDown(MouseEventArgs e) {
      if (e.Button == MouseButtons.Left) this.Capture = true;
      base.OnMouseDown(e);
    }
    protected override void OnMouseMove(MouseEventArgs e) {
      if (e.Button == MouseButtons.Left) {
        // Your dragging logic here...
        Console.WriteLine(e.Location);
      }
      base.OnMouseMove(e);
    }
  }
0
0

I think that you are after Mouse.Capture, or something similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.