預設 ToolStripButton 滑鼠懸停背景為藍色,需自訂背景顏色與邊框樣式(例:滑鼠進入變黑色)。
ToolStripButton tsb = (ToolStripButton)sender;
Rectangle rectButton = tsb.Bounds;
Point p = toolStrip1.PointToClient(Control.MousePosition);
if (rectButton.Contains(p)) {
e.Graphics.Clear(SystemColors.ControlText); // 背景設為黑色
if (tsb.Image != null) {
e.Graphics.DrawImage(tsb.Image,
new Point((e.ClipRectangle.Width - tsb.Image.Width) / 2,
(e.ClipRectangle.Height - tsb.Image.Height) / 2));
}
}
在 Paint 事件中判斷滑鼠是否在按鈕區域,手動繪製背景與圖片置中。