1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Collections;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics;
namespace AccountValue
{
[ProvideProperty("Draggable", typeof(Control))]
public class DragExtender : System.ComponentModel.Component, IExtenderProvider
{
private const int WM_SYSCOMMAND = 0x112;
private const int MOUSE_MOVE = 0xF012;
[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd,
int msg , int wParam , ref int lParam);
[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd,
int msg , int wParam , int[] lParam);
[DllImport("user32")]
public static extern int ReleaseCapture(IntPtr hwnd);
private System.ComponentModel.Container _container;
public DragExtender()
{
_container = new System.ComponentModel.Container();
}
#region IExtenderProvider Members
public bool CanExtend(object extendee)
{
// TODO: Add DragExtender.CanExtend implementation
return (extendee is Control);
//return false;
}
#endregion
public bool GetDraggable(Control control)
{
foreach(Control ctrl in _container.Components)
{
if (control==ctrl) return true;
}
return false;
}
public void SetDraggable(Control control, bool value)
{
if (value)
{
if (!GetDraggable(control))
{
this._container.Add(control);
control.MouseDown+=new MouseEventHandler(control_MouseDown);
}
}
else
if (GetDraggable(control))
{
_container.Remove(control);
}
}
private Form m_form = null;
public Form Form
{
get { return m_form; }
set { m_form = value; }
}
private void control_MouseDown(object sender, MouseEventArgs e)
{
if (!DesignMode && m_form!=null)
{
Control control = sender as Control;
ReleaseCapture(control.Handle);
int nul =0;
SendMessage(m_form.Handle, WM_SYSCOMMAND, MOUSE_MOVE, ref nul);
}
}
}
}
|