diff options
author | Sebastian | 2011-01-28 11:03:08 +0100 |
---|---|---|
committer | Sebastian | 2011-01-28 11:03:08 +0100 |
commit | 4b6dc1d93f19cad0e096c1632b660aecb0bc3673 (patch) | |
tree | 4a4c18c0f311e013e56ba113d161b6b1e87a8eaa /AccountValue/DragExtender.cs | |
download | logintool-4b6dc1d93f19cad0e096c1632b660aecb0bc3673.tar.gz logintool-4b6dc1d93f19cad0e096c1632b660aecb0bc3673.tar.xz logintool-4b6dc1d93f19cad0e096c1632b660aecb0bc3673.zip |
initial import of logintool svn
Diffstat (limited to 'AccountValue/DragExtender.cs')
-rw-r--r-- | AccountValue/DragExtender.cs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/AccountValue/DragExtender.cs b/AccountValue/DragExtender.cs new file mode 100644 index 0000000..0beecf2 --- /dev/null +++ b/AccountValue/DragExtender.cs @@ -0,0 +1,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);
+ }
+ }
+ }
+}
\ No newline at end of file |