C # (winform) add a background image for the button

1. Since it is a background image

    So here should be used Button.BackgroudImage = ""; to set the picture

         You should not use Button.Image = ""; 

   Because the use BackgroudImage to set the background image, we can also use

    BackgroundImageLayout to adjust the picture, so that a better picture displayed on a button

    Commonly used:

technology sharing
1 this.btnReset.BackgroundImage = global :: Test.Properties.Resources.btn_reset_out; // set the image path 
2 this.btnReset.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; // set the image display mode, Stretch It represents fill button, button if the picture is not large, it will stretch the picture
View Code

2. Then you will see that despite the addition of a background image, and also set up stretching the picture, but the effect is still far from satisfactory

   technology sharing

   How there will be a border ah, ah how ugly it was, since there is a border, then canceled it borders

   technology sharing

     However, did not find the button of the Border property, but found FlatStyle property (a property determines the appearance of controls),

     Regardless, the first one by one to try anything, and finally Flat feel more in line with our tastes,

       technology sharing

     Giving the impression that the border is not very thick, but still looks very uncomfortable, how there is a little white box ah

     technology sharing

     Just could not find the Border property, the original is hidden in the FlatAppearance below, and directly into BorderSize 0

     Effect immediately becomes as follows:

        technology sharing

      Oh, that annoying white box was gone, the overall look and feel comfortable with a lot of ah,

     But careful you certainly can see, because the button is rounded background image, actually there on the four corners

     That innocent people to leave the white border! ! ! ! , Running the effect is more pronounced, particularly when the mouse moves in and out:

     technology sharing and technology sharing

     Left mouse is moved before, looks very comfortable; and when the mouse is moved into the right, rub, four corners, that was obvious, obsessive-compulsive disorder, I simply can not accept it!

     From the beginning to now toss so long, appeared to get the time, there is still such a small problem ???? do the authors is a Microsoft bug ???

     I finally found or wrong, the solution is as follows:

  technology sharing

     Or in just the FlatAppearance property, but this change is MouseDownBackColor, MouseOverBackColor are set to Transparent (transparent color)

     Finally, of course, set about

     this.btnReset.BackColor = System.Drawing.Color.Transparent;

Reproduced in: https: //www.cnblogs.com/zhangchenliang/p/4335372.html

Guess you like

Origin blog.csdn.net/weixin_33836874/article/details/93495537