Each button has a Rectangle property,
whose values you can use, in context of the current mouse coordinates and
compute the button in question.
whose values you can use, in context of the current mouse coordinates and
compute the button in question.
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;
}