Example #1
0
        protected virtual TabPage OverTab()
        {
            TabPage over = null;

            Point pt = this.PointToClient(Cursor.Position);

            User32.TCHITTESTINFO mouseInfo = new User32.TCHITTESTINFO(pt, User32.TabControlHitTest.TCHT_ONITEM);
            int currentTabIndex            = User32.SendMessage(this.Handle, User32._TCM_HITTEST, IntPtr.Zero, ref mouseInfo);

            if (currentTabIndex > -1)
            {
                Rectangle currentTabRct = this.GetTabRect(currentTabIndex);

                if (currentTabIndex == 0)
                {
                    currentTabRct.X += _tabHOffset;
                }

                if (currentTabRct.Contains(pt))
                {
                    over = this.TabPages[currentTabIndex] as TabPage;
                }
            }

            return(over);
        }
        protected override bool GetHitTest(Point point)
        {
            ISelectionService _selectionService = (ISelectionService)GetService(typeof(ISelectionService));

            if (_selectionService != null)
            {
                object selectedObject = _selectionService.PrimarySelection;
                if (selectedObject != null && selectedObject.Equals(Control))
                {
                    Point p = Control.PointToClient(point);

                    User32.TCHITTESTINFO hti = new User32.TCHITTESTINFO(p, User32.TabControlHitTest.TCHT_ONITEM);

                    Message m = new Message();
                    m.HWnd = Control.Handle;
                    m.Msg  = User32._TCM_HITTEST;

                    IntPtr lParam = Marshal.AllocHGlobal(Marshal.SizeOf(hti));
                    Marshal.StructureToPtr(hti, lParam, false);
                    m.LParam = lParam;

                    base.WndProc(ref m);
                    Marshal.FreeHGlobal(lParam);

                    if (m.Result.ToInt32() != -1)
                    {
                        return(hti.flags != User32.TabControlHitTest.TCHT_NOWHERE);
                    }
                }
            }

            return(false);
        }