C # (WinForm) to add a background picture to a button

Source: Internet
Author: User
Tags transparent color

1. If you are adding a background image

So here should use button.backgroudimage = ""; To set the picture

And should not use Button.image = "";

Because using Backgroudimage to set the background image, we can also use the

BackgroundImageLayout to adjust the picture so that the picture is better displayed on the button

Commonly used:

1  This Global:: Test.Properties.Resources.btn_reset_out; // set the path to the picture 2             this. btnreset.backgroundimagelayout = System.Windows.Forms.ImageLayout.Stretch; // Set the display mode of the picture, stretch to fill the button, if the picture is not large enough, the picture will be stretched
View Code

2. Then you will see that despite the addition of a background image, but also set up a stretch of the picture, but the effect is very bad

How can there be a border ah, this how ugly ah, since there is a border, then cancel the border bar

However, the border property of the button was not found, but the FlatStyle property was found (a property that determines the appearance of the control).

Regardless of, first try to what changes, finally flat feel more in line with our taste,

It's a very thick frame, but it still looks uncomfortable, and there's a little white box.

Just can't find the border property, the original is hidden in the flatappearance below, direct bordersize changed to 0

The effect immediately becomes as follows:

Oh, that annoying white box also disappeared, the overall look feel comfortable a lot of ah,

But careful you must also see, because the background picture of the button is rounded, the four corners on the incredibly still have

That ghost white border!!!! , the effect of running is more obvious, especially when the mouse moves in and out:

and

The left picture is the mouse to move in front, looks very comfortable, and the right picture is the mouse to move in, rub, four corner, this is too obvious, obsessive-compulsive I can not accept it!

From the beginning to now toss for so long, see to be done when, incredibly still have such a small problem. Microsoft's bug is not a problem???

Finally found or I was wrong, the solution is as follows:

Still in just that flatappearance attribute, but this time change is Mousedownbackcolor,mouseoverbackcolor are set to Transparent (transparent color)

And, of course, the final setup.

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

C # (WinForm) to add a background picture to a button

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.