Home  >  Article  >  Backend Development  >  Detailed explanation of the toolStripButton custom background application sample source code of the c#Winform program

Detailed explanation of the toolStripButton custom background application sample source code of the c#Winform program

黄舟
黄舟Original
2017-03-13 11:24:212489browse

C# The background of the toolStripButton in the toolStrip of the Winform program is blue. How to change the color and style of the background and border?

To implement this function, you need to override the Paint method of toolStripButton

Here are just ideas and methods to solve the problem, as shown below, when the mouse Move to the button, the background will change to black


The implementation code is as follows:

            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));
                }
            }

The above is the detailed content of Detailed explanation of the toolStripButton custom background application sample source code of the c#Winform program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn