How could I click in a control and drag (not Drag and Drop) out of it but still follow the event as long as the button is clicked?
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 restricte开发者_C百科d 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.
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);
}
}
I think that you are after Mouse.Capture, or something similar.
精彩评论