简体   繁体   English

winform中的图标按钮布局

[英]Icon button layout in winform

I'm working on Windows 8, VS 2012. I added a round icon to my button: 我正在使用Windows 8,VS 2012.我在我的按钮上添加了一个圆形图标:

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 将按钮的FlatStyle属性更改为Flat
  • Set its BackColor property to Transparent 将其BackColor属性设置为Transparent
  • In FlatAppearance Set BorderSize to 0. FlatAppearance设置BorderSize为0。
  • In FlatAppearance You can also set MouseDownBackColor and MouseOverBackColor to back color of form or the color you want. FlatAppearance您还可以将MouseDownBackColorMouseOverBackColor设置为背景颜色或所需颜色。

在此输入图像描述

You can make you control have a transparent background and then use a transparent PNG as the icon and voila. 你可以让你控制透明背景,然后使用透明的PNG作为图标和瞧。

See this Microsoft Article with regards to creating transparent backgrounds on controls 有关在控件上创建透明背景的信息,请参阅此Microsoft文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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