Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/WinFormsUI/Docking/DragForm.cs @ 2216

Last change on this file since 2216 was 2134, checked in by gkronber, 15 years ago

Added up to date source of Weifen Luo dock panel suit in a separate project (and added strong name key). Removed binary versions of Weifen Luo dock panel suite and references to it. #687 (Update AdvancedOptimizationFrontend to use more recent version of Weifen Luo Docking library)

File size: 2.1 KB
RevLine 
[2134]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_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
56    public virtual void Show(bool bActivate)
57    {
58      if (bActivate)
59        Show();
60      else
61        NativeMethods.ShowWindow(Handle, (int)Win32.ShowWindowStyles.SW_SHOWNOACTIVATE);
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.