نقل قول:
using System;
using System.Runtime.InteropServices;
namespace Tarahi
{
internal static class HelperMethods
{
public static void MoveObject(IntPtr hWnd)
{
SafeNativeMethods.ReleaseCapture();
SafeNativeMethods.SendMessage(hWnd, SafeNativeMethods.WM_NCLBUTTONDOWN, SafeNativeMethods.HTCAPTION, 0);
}
}
}
بعدش یه کلاس دیگه با نام SafeNativeMethods میسازی و اینو میزاری توش :
نقل قول:
using System;
using System.Runtime.InteropServices;
namespace Tarahi
{
internal static class SafeNativeMethods
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int SendMessage(
IntPtr hWnd,
[param: MarshalAs(UnmanagedType.U4)]
uint Msg,
[param: MarshalAs(UnmanagedType.U4)]
uint wParam,
[param: MarshalAs(UnmanagedType.I4)]
int lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ReleaseCapture();
public const uint WM_NCLBUTTONDOWN = 0xA1; // 161
public const uint HTCAPTION = 2;
}
}
آخرش هم این کد رو توی event MouseDown کنترل خود مثلا پیکچر باکس می زازی :