public void ShowWindow(Point pnt, FOLDERVIEWMODE fvmCurrentMode) { const uint SWP_NOACTIVATE = 0x0010; const int SW_SHOWNOACTIVATE = 4; trackBar1.Value = ModeToInt(fvmCurrentMode); // set the slider of trackbar under mouse position RECT rct = GetThumbRect(); Point pntCenter = new Point(rct.left + rct.Width / 2, rct.top + rct.Height / 2); Rectangle rctScreen = Screen.FromPoint(pnt).Bounds; pnt.X = pnt.X - pntCenter.X; pnt.Y = pnt.Y - pntCenter.Y; // ensure visible in the screen if (pnt.X < rctScreen.Left) { pnt.X = rctScreen.Left; } else if (pnt.X + Width > rctScreen.Right) { pnt.X = rctScreen.Right - Width; } if (pnt.Y < rctScreen.Top) { pnt.Y = rctScreen.Top; } else if (pnt.Y + Height > rctScreen.Bottom) { pnt.Y = rctScreen.Bottom - Height; } PInvoke.SetWindowPos(Handle, (IntPtr)(-1), pnt.X, pnt.Y, Width, Height, SWP_NOACTIVATE); PInvoke.ShowWindow(Handle, SW_SHOWNOACTIVATE); trackBar1.Focus(); }
public void HideWindow() { PInvoke.ShowWindow(Handle, 0); }