简体   繁体   中英

Icon button layout in winform

I'm working on Windows 8, VS 2012. I added a round icon to my button:

this.btn.Image = Properties.Resources.icon;
this.btn.Size = Properties.Resources.icon.Size;

Also my form has background image:

this.BackgroundImage = Properties.Resources.sunset;

But I'm getting ugly form, where my icon button is square: the round image in the middle and gray color in the corners.

The question is how can I display form background instead of gray color?

在此输入图像描述

Thank you for your attention

You can set some property of your button to gain what you need:

  • Change FlatStyle property of your button to Flat
  • Set its BackColor property to Transparent
  • In FlatAppearance Set BorderSize to 0.
  • In FlatAppearance You can also set MouseDownBackColor and MouseOverBackColor to back color of form or the color you want.

在此输入图像描述

You can make you control have a transparent background and then use a transparent PNG as the icon and voila.

See this Microsoft Article with regards to creating transparent backgrounds on controls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM