6

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?

enter image description here

Thank you for your attention

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
Eucalyptus
  • 67
  • 1
  • 1
  • 6
  • 2
    Transparency in winforms is a hack and doesn't really exist. The transparency colour is determined from the BackgroundColor of the element behind it I believe – Sayse Oct 06 '15 at 07:44
  • 1
    Are you using Mono over Linux or are you working on Windows? On Linux, WinForms implementation is already ugly by itself... – Baltasarq Oct 06 '15 at 07:44
  • Possible duplicate of [Round shaped buttons](http://stackoverflow.com/questions/3708113/round-shaped-buttons) – TaW Oct 06 '15 at 08:18
  • Either make the the grey areas brown (if the Backcolor doesn't change) or use the 2nd answer from the [post here](http://stackoverflow.com/questions/3708113/round-shaped-buttons) – TaW Oct 06 '15 at 08:19
  • @TaW Added the RoundButton code in form.cs and the follow text appears in form.cs[Design] "To add components to your class, drag them..." instead of existing form. – Eucalyptus Oct 06 '15 at 08:55
  • Use `PictureBox` instead of button and also use interlaced PNG Files to make your life easy. – Onel Sarmiento Oct 06 '15 at 09:02
  • um, what about the missing part of the error message ? You can drag a self-written control from the top of the toolbox, if it is error-free. Or go for reza's answer, working a little on the image.. – TaW Oct 06 '15 at 09:21

2 Answers2

8

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.

enter image description here

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
0

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

TheDanMan
  • 1,746
  • 1
  • 17
  • 22