Each button has a Rectangle property,
whose values you can use, in context of the current mouse coordinates and
compute the button in question.

解决方案 »

  1.   

    判断鼠标指针是否进入ToolBar的边框之内。
      

  2.   

    You can use the TB_HITTEST message to find out which tool button
    is under the mouse in the toolbar's MouseMove event.such as:
    [DllImport("User32", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(
          IntPtr hWnd, 
          uint msg, 
          uint wParam, 
          ref Point lParam);    public const int TB_HITTEST = 1093; // WM_USER + 69;    private void toolBar_MouseMove(
          object sender,
          System.Windows.Forms.MouseEventArgs e) 
        {
          Point pt = new Point(e.X, e.Y);
          IntPtr result = 
            SendMessage(this.toolBar.Handle, TB_HITTEST, 0, ref pt);
          
          int buttonIndex = result.ToInt32();      // Low and high indexes of the visible toolbar buttons.
          const int lowVisibleButtonIndex = 0;
          const int highVisibleButtonIndex = 7;      if ((buttonIndex >= lowVisibleButtonIndex) && 
              (buttonIndex <= highVisibleButtonIndex))
            this.statusBar.Text =
              this.toolBar.Buttons[buttonIndex].ToolTipText; 
        }