Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DragForm.cs

Last change on this file was 8616, checked in by mkommend, 12 years ago

#1939: Added DockPanelSuite 2.7.0 to ExtLibs.

File size: 2.6 KB
Line 
1using System;
2using System.Windows.Forms;
3
4namespace WeifenLuo.WinFormsUI.Docking
5{
6    // Inspired by Chris Sano's article:
7    // http://msdn.microsoft.com/smartclient/default.aspx?pull=/library/en-us/dnwinforms/html/colorpicker.asp
8    // In Sano's article, the DragForm needs to meet the following criteria:
9    // (1) it was not to show up in the task bar;
10    //     ShowInTaskBar = false
11    // (2) it needed to be the top-most window;
12    //     TopMost = true (not necessary here)
13    // (3) its icon could not show up in the ALT+TAB window if the user pressed ALT+TAB during a drag-and-drop;
14    //     FormBorderStyle = FormBorderStyle.None;
15    //     Create with WS_EX_TOOLWINDOW window style.
16    //     Compares with the solution in the artile by setting FormBorderStyle as FixedToolWindow,
17    //     and then clip the window caption and border, this way is much simplier.
18    // (4) it was not to steal focus from the application when displayed.
19    //     User Win32 ShowWindow API with SW_SHOWNOACTIVATE
20    // In addition, this form should only for display and therefore should act as transparent, otherwise
21    // WindowFromPoint will return this form, instead of the control beneath. Need BOTH of the following to
22    // achieve this (don't know why, spent hours to try it out :( ):
23    //  1. Enabled = false;
24    //  2. WM_NCHITTEST returns HTTRANSPARENT
25    internal class DragForm : Form
26    {
27        public DragForm()
28        {
29            FormBorderStyle = FormBorderStyle.None;
30            ShowInTaskbar = false;
31            SetStyle(ControlStyles.Selectable, false);
32            Enabled = false;
33        }
34
35        protected override CreateParams CreateParams
36        {
37            get
38            {
39                CreateParams createParams = base.CreateParams;
40                createParams.ExStyle |= (int)(Win32.WindowExStyles.WS_EX_NOACTIVATE | Win32.WindowExStyles.WS_EX_TOOLWINDOW);
41                return createParams;
42            }
43        }
44
45        protected override void WndProc(ref Message m)
46        {
47            if (m.Msg == (int)Win32.Msgs.WM_NCHITTEST)
48            {
49                m.Result = (IntPtr)Win32.HitTest.HTTRANSPARENT;
50                return;
51            }
52
53            base.WndProc(ref m);
54        }
55        //The form can be still activated by explicity calling Activate
56        protected override bool ShowWithoutActivation
57        {
58            get { return true; }
59        }
60        public virtual void Show(bool bActivate)
61        {
62                Show();
63
64                if (bActivate)
65                    Activate();
66        }
67    }
68}
Note: See TracBrowser for help on using the repository browser.