[DllImport("user32.dll")]
static extern bool ReleaseCapture();
<DllImport("user32.dll")> _
Private Shared Function ReleaseCapture() As Boolean
End Function
None.
None.
ReleaseCapture will delegate mousedown events to underlying controls.
Please add some!
You can use the ReleaseCapture() function to provide drag functionality. for example the following code will allow the user to drag a control around a form (you'll have to assign this code to the mousedown event):
[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int msg , int wParam , ref int lParam);
[DllImport("user32")]
public static extern int ReleaseCapture(IntPtr hwnd);
private const int WM_SYSCOMMAND = 0x112;
private const int MOUSE_MOVE = 0xF012;
private void control_MouseDown(object sender, MouseEventArgs e)
{
Control ctrl = sender as Control;
ReleaseCapture(ctrl.Handle);
int nul =0;
SendMessage(ctrl.Handle, WM_SYSCOMMAND, MOUSE_MOVE, ref nul);
}
Capture property on System.Windows.Forms.Control
Do you know one? Please contribute it!
Public Class Form1
Private MouseDown1 As Boolean
Private PosDiff As Point
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Me.TopMost = True
End Sub
Private Sub PictureBox3_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox3.MouseMove
If Not MouseDown1 Then Exit Sub
If Not System.Windows.Forms.SystemInformation.MouseButtonsSwapped() Then
If Not e.Button = Windows.Forms.MouseButtons.Left Then Exit Sub
Else
If Not e.Button = Windows.Forms.MouseButtons.Right Then Exit Sub
End If
Me.Location = New Point(Cursor.Position().X - PosDiff.X, Cursor.Position().Y - PosDiff.Y)
End Sub
Private Sub PictureBox3_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox3.MouseUp
MouseDown1 = False
End Sub
Private Sub PictureBox3_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox3.MouseDown
MouseDown1 = True
PosDiff = New Point(Cursor.Position().X - Me.Location.X, Cursor.Position().Y - Me.Location.Y)
End Sub
End Class