C# Winform程序的toolStrip中toolStripButton的背景是蓝色的,如何改变背景及边框的颜色和样式呢?

实现此功能需要重写toolStripButton的Paint方法

这里只是给出解决问题的思路和方法,如下图,当鼠标移到按钮上,背景会变为黑色

c#Winform程序的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));
                }
            }
源码下载:c#Winform程序的toolStripButton自定义背景应用示例源码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-10-23
  • 2021-03-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案