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

黄舟
Release: 2017-03-13 11:24:21
Original
2429 people have browsed it

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));
                }
            }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!