« Embedded Resources, ImageLists | Main | Buffered Console.Out »

ToolBar button image tricks

Changing button images for mouse over highlighting with a .NET ToolBar is a bit tricky.

This works with a little flicker, where %3==0 are normal images, & %3==2 are highlight images.

         private void toolBar_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {

              foreach (ToolBarButton b in toolBar.Buttons) {

                  if (b.Style == ToolBarButtonStyle.Separator || !b.Enabled) continue;

                  if (b.Rectangle.Contains(e.X, e.Y))

                       b.ImageIndex = (b.ImageIndex / 3) * 3 + 2;

                  else

                       b.ImageIndex = (b.ImageIndex / 3) * 3;

              }

         }

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)