protected override bool GetHitTest(Point point) { if (SelectionService.PrimarySelection == Control) { TCHITTESTINFO _tabControlHitTestInfo = new TCHITTESTINFO { Point = Control.PointToClient(point), Flags = 0 }; Message _message = new Message { HWnd = Control.Handle, Msg = 0x130D }; IntPtr _longIntParameter = Marshal.AllocHGlobal(Marshal.SizeOf(_tabControlHitTestInfo)); Marshal.StructureToPtr(_tabControlHitTestInfo, _longIntParameter, false); _message.LParam = _longIntParameter; base.WndProc(ref _message); Marshal.FreeHGlobal(_longIntParameter); if (_message.Result.ToInt32() != -1) { return(_tabControlHitTestInfo.Flags != TabControlHitTest.TCHT_NOWHERE); } } return(false); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); HotTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); }
private void _tc_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { var HTI = new TCHITTESTINFO(e.X, e.Y); var hotTab = _tc.TabPages[SendMessage(_tc.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI)]; _tc.SelectedIndex = hotTab.TabIndex; } for (var i = 0; i < _tc.TabPages.Count; i++) { var tabRect = this._tc.GetTabRect(i); tabRect.Inflate(-2, -2); var closeImage = new Bitmap(Resources._5657_close); var imageRect = new Rectangle( (tabRect.Right - closeImage.Width), tabRect.Top + (tabRect.Height - closeImage.Height) / 2, closeImage.Width, closeImage.Height); if (imageRect.Contains(e.Location) && _tc.TabPages.Count > 1) { _tc.TabPages.RemoveAt(i); break; } } }
protected override bool GetHitTest(Point point) { if (this.SelectionService.PrimarySelection == this.Control) { TCHITTESTINFO hti = new TCHITTESTINFO(); hti.pt = this.Control.PointToClient(point); hti.flags = 0; Message m = new Message(); m.HWnd = this.Control.Handle; m.Msg = 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 != TabControlHitTest.TCHT_NOWHERE); } } return(false); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); HotTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); if (e.Button != MouseButtons.Left) { return; } Rectangle r = new Rectangle(DragStartPosition, Size.Empty); r.Inflate(SystemInformation.DragSize); TabPage tp = HoverTab(); if (tp != null) { if (!r.Contains(e.X, e.Y)) { this.DoDragDrop(tp, DragDropEffects.All); } } DragStartPosition = Point.Empty; }
/* * protected override void OnMouseEnter(EventArgs e) * { * Point p = PointToClient(Cursor.Position); * TCHITTESTINFO HTI = new TCHITTESTINFO(p.X, p.Y); * HoveredTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); * Console.WriteLine("Entered: {0}", HoveredTabIndex); * * if(HoveredTabIndex!=SelectedIndex) * { * Rectangle recBounds = this.GetTabRect(HoveredTabIndex); * Rectangle lineRect = new Rectangle(recBounds.X, recBounds.Y, recBounds.Width - 4, recBounds.Height); * this.CreateGraphics().DrawRectangle(SystemPens.ActiveBorder, lineRect); * CurrentIndex = HoveredTabIndex; * } * * Console.WriteLine("Current: {0}", CurrentIndex); * base.OnMouseEnter(e); * } */ protected override void OnMouseMove(MouseEventArgs e) { //Point p = PointToClient(Cursor.Position); TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); HoveredTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); if (HoveredTabIndex != SelectedIndex) { TabPage page = TabPages[SelectedIndex]; page.MouseEnter += Page_MouseEnter;; Rectangle recBounds = this.GetTabRect(HoveredTabIndex < 0 ? 0 : HoveredTabIndex); Rectangle lineRect = new Rectangle(recBounds.X, recBounds.Y, recBounds.Width - 4, recBounds.Height); this.CreateGraphics().DrawRectangle(SystemPens.ActiveBorder, lineRect); CurrentIndex = HoveredTabIndex; } else { Invalidate(); } base.OnMouseMove(e); }
/* protected override void OnMouseEnter(EventArgs e) { Point p = PointToClient(Cursor.Position); TCHITTESTINFO HTI = new TCHITTESTINFO(p.X, p.Y); HoveredTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); Console.WriteLine("Entered: {0}", HoveredTabIndex); if(HoveredTabIndex!=SelectedIndex) { Rectangle recBounds = this.GetTabRect(HoveredTabIndex); Rectangle lineRect = new Rectangle(recBounds.X, recBounds.Y, recBounds.Width - 4, recBounds.Height); this.CreateGraphics().DrawRectangle(SystemPens.ActiveBorder, lineRect); CurrentIndex = HoveredTabIndex; } Console.WriteLine("Current: {0}", CurrentIndex); base.OnMouseEnter(e); } */ protected override void OnMouseMove(MouseEventArgs e) { //Point p = PointToClient(Cursor.Position); TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); HoveredTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); if (HoveredTabIndex != SelectedIndex) { TabPage page = TabPages[SelectedIndex]; page.MouseEnter += Page_MouseEnter; ; Rectangle recBounds = this.GetTabRect(HoveredTabIndex < 0 ? 0 : HoveredTabIndex); Rectangle lineRect = new Rectangle(recBounds.X, recBounds.Y, recBounds.Width - 4, recBounds.Height); this.CreateGraphics().DrawRectangle(SystemPens.ActiveBorder, lineRect); CurrentIndex = HoveredTabIndex; } else { Invalidate(); } base.OnMouseMove(e); }
private static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam, ref TCHITTESTINFO lParam);
internal static extern int SendMessage( IntPtr hwnd, int tMsg, IntPtr wParam, ref TCHITTESTINFO lParam);
public static extern IntPtr SendMessage([In] HandleRef hWnd, [In] uint msg, [In] IntPtr wParam, [In] ref TCHITTESTINFO lParam);
public int HitTest(int x, int y) { TCHITTESTINFO htInfo = new TCHITTESTINFO(x, y); int idx = SendMessage(this.Handle, (int)TabCtrlMessage.HITTEST, IntPtr.Zero, ref htInfo).ToInt32(); return idx; }
private void ContentFileTabs_MouseDown(object sender, MouseEventArgs e) { TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); TabPage tp = ContentFileTabs.TabPages[SendMessage(ContentFileTabs.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI)]; ContentFileTabs.SelectedTab = tp; ContentFileTabs.ContextMenuStrip = cmContentTab; }
} // 1.0.020 protected override bool GetHitTest(System.Drawing.Point point) // 1.0.020 { // 1.0.020 if (this.SelectionService.PrimarySelection == this.Control) // 1.0.020 { // 1.0.020 TCHITTESTINFO hti = new TCHITTESTINFO(); // 1.0.020 hti.pt = this.Control.PointToClient(point); // 1.0.020 hti.flags = 0; // 1.0.020 System.Windows.Forms.Message m = new System.Windows.Forms.Message(); // 1.0.020 m.HWnd = this.Control.Handle; // 1.0.020 m.Msg = TCM_HITTEST; // 1.0.020 IntPtr lparam = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(hti)); // 1.0.020 System.Runtime.InteropServices.Marshal.StructureToPtr(hti, lparam, false); // 1.0.020 m.LParam = lparam; // 1.0.020 base.WndProc(ref m); // 1.0.020 System.Runtime.InteropServices.Marshal.FreeHGlobal(lparam); // 1.0.020 if (m.Result.ToInt32() != -1) // 1.0.020 { // 1.0.020 return hti.flags != TabControlHitTest.TCHT_NOWHERE; // 1.0.020 } // 1.0.020 } // 1.0.020 return false; // 1.0.020 } // 1.0.020
public static extern IntPtr SendMessage(HWND hWnd, TabControlMessage Msg, int wParam, ref TCHITTESTINFO item);
internal static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, ref TCHITTESTINFO lParam);
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); TCHITTESTINFO HTI = new TCHITTESTINFO(e.X, e.Y); HotTabIndex = SendMessage(this.Handle, TCM_HITTEST, IntPtr.Zero, ref HTI); if (e.Button != MouseButtons.Left) return; Rectangle r = new Rectangle(DragStartPosition, Size.Empty); r.Inflate(SystemInformation.DragSize); TabPage tp = HoverTab(); if (tp != null) { if (!r.Contains(e.X, e.Y)) this.DoDragDrop(tp, DragDropEffects.All); } DragStartPosition = Point.Empty; }