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

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

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

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自己定义背景应用演示样例源代码

相关文章:

  • 2021-07-09
  • 2022-12-23
  • 2021-08-21
  • 2021-11-17
  • 2022-12-23
  • 2021-08-21
  • 2022-02-02
  • 2022-12-31
猜你喜欢
  • 2021-07-08
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-29
相关资源
相似解决方案